this is the question and i wrote the following code below . but felling problem in that code . hekp needed .

Write a program that reads from keyboard a string and number N. Program should display to the screen the string N times. Use “while” loop. Example input: abc 2 Example output: abc abc

String string = ""; String m = ""; try{ InputStreamReader input = new InputStreamReader(System.in); BufferedReader reader = new BufferedReader(input); string = reader.readLine(); m = reader.readLine(); int num = Integer.parseInt(m); while(num<=num){ System.out.println(string+num); }

}
 catch (NumberFormatException ex) 
        {
            System.out.println("Not a number !");
        }   
        catch (IOException e) 
        {
        e.printStackTrace();

}

asked 20 Mar '15, 11:36

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
431922
accept rate: 0%


declare another int like int a=0; while (a<num) { System.out.println(String); a++; }

link

answered 20 Mar '15, 14:10

Reem's gravatar image

Reem
39118
accept rate: 0%

while(num<=num)

This is infinite loop (condition num <= num, like the num = num, will be always true).

link

answered 09 Apr, 05:33

noelo's gravatar image

noelo
102
accept rate: 0%

It works.

   BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String s = reader.readLine();
    int N = Integer.parseInt(reader.readLine());

    while(N>0)
   {
   System.out.println(s);
   N--;
    }
link

answered 26 Nov, 19:49

Javier%20Pe%C3%B1a's gravatar image

Javier Peña
1
accept rate: 0%

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:

×52
×34
×6

Asked: 20 Mar '15, 11:36

Seen: 1,130 times

Last updated: 26 Nov, 19:49