Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:15:44+00:00 2026-06-18T12:15:44+00:00

I have an input: aN b c a1 a2 a3 … aN for example:

  • 0

I have an input:

aN b c
a1 a2 a3 ... aN

for example:

4 3 2
2 1 2 1 (I have here 'a' numbers, a = 4)
5 6 3
3 9 5 7 3 (I have here 'a' numbers, a = 5)
0 0 0

I want to stop reading an input when a or b or c will equal 0. I tried this:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

public class Test {

    public static void main(String[] args) throws IOException {

        InputStreamReader converter = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(converter);
        String line = "";
        int a = -1, b = -1, c = -1;
        LinkedList<Integer> list = new LinkedList<>();

        while (a != 0 && b != 0 && c != 0) 
        {
            line = in.readLine();
            String tmp[] = line.split(" ");
            a = Integer.parseInt(tmp[0]);
            b = Integer.parseInt(tmp[1]);
            c = Integer.parseInt(tmp[2]);
            System.out.println("a = " + a + ", b = " + b + ", c = " + c);
            line = in.readLine();
            list.clear();
            tmp = line.split(" ");
            for (int i = 0; i < tmp.length; i++) {
                list.add(new Integer(Integer.valueOf(tmp[i])));
            }
            System.out.println("List = 4 3 2" + list);   
        }   
    }        
}

but with this simple input:

4 3 2
2 1 2 1
5 6 3
3 9 5 7 3
0 0 0

even if I type 3 zeros, my program still waits for an input. How to improve it?

EDIT:

Guy you misunderstood. I NEED to have a second readline cause I need to read a second (fourth, sixth) line of input …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:15:45+00:00Added an answer on June 18, 2026 at 12:15 pm
    while (true) 
    {
            line = in.readLine();
            String tmp[] = line.split(" ");
            a = Integer.parseInt(tmp[0]);
            b = Integer.parseInt(tmp[1]);
            c = Integer.parseInt(tmp[2]);
            if (a == 0 || b == 0 || c == 0) {
                break;
            }
            System.out.println("a = " + a + ", b = " + b + ", c = " + c);
            line = in.readLine();
            list.clear();
            tmp = line.split(" ");
            for (int i = 0; i < tmp.length; i++) {
                list.add(new Integer(Integer.valueOf(tmp[i])));
            }
            System.out.println("List = 4 3 2" + list);   
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have input data in a flattened file. I want to normalize this data,
I have input text element, I want: when I write some symbol in this
I have an input that will have input between 3-5 alphanumeric characters. I want
For ex: I have input with this value: (099) 123 45 67 I want
I have input.txt and I want to search for a string and extract a
i have input xml as <content> <date> <day>14</day> <month>06</month> <year>2012</year> </date> </content> want it
I have this input text and an input button...I am looking to have them
I have input checkbox something like this.. <input class=inputchbox id=Pchk type=checkbox name=check value=<%=Model.ID%> />
I have input data that contain lines like this: -0.438185 -0.766791 0.695282 0.759100 0.034400
simple question: I have input fields with inside-labels! Just like the search-box on this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.