the following code does not pass the test pleae help

public static void readData() {
    //add your code here
    List<Integer> list = new ArrayList<Integer>();
    try
    {
        while (true)
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String str = reader.readLine();
            int a = Integer.parseInt(str);
            list.add(a);
        }
    }
    catch (Exception e)
    {
        for(int j=0; j<list.size();j++)
        {
            System.out.println(list.get(j));
        }
    }
}

asked 30 Apr '15, 12:17

Reem's gravatar image

Reem
39118
accept rate: 0%

edited 06 May '15, 10:59


Yes, correct, but must be not inside the loop

link

answered 11 May '15, 05:24

Hehabr's gravatar image

Hehabr
262
accept rate: 25%

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

Line 8 ?

link

answered 08 May '15, 18:26

Hehabr's gravatar image

Hehabr
262
accept rate: 25%

edited 08 May '15, 18:28

this line works correct i am able to read data..

(10 May '15, 12:59) Reem
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×11
×9
×2
×1
×1

Asked: 30 Apr '15, 12:17

Seen: 1,804 times

Last updated: 11 May '15, 05:24