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

   public class Solution
{
    public static void main(String[] args) throws Exception
    {
        //add your code here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        String sX = br.readLine();
        //String s = br.readLine();
        int x = Integer.parseInt(sX);
        //for(int i=0; i<x; i++)
        int i=0;
        while(i<x)
        {
            System.out.println(s);
            i++;
        }

    }
}

i cannot past the test with this code

asked 26 Jul '17, 17:55

genek's gravatar image

genek
172
accept rate: 0%

edited 26 Jul '17, 17:56


remove comments?

link

answered 27 Jul '17, 11:49

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

Why should we creat a new variable without any reason? Try this:

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

answered 27 Jul '17, 08:48

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

edited 27 Jul '17, 08:48

It doesn't help.

link

answered 27 Jul '17, 09:37

genek's gravatar image

genek
172
accept rate: 0%

LOL it helps

link

answered 27 Jul '17, 17:54

genek's gravatar image

genek
172
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:

×67
×35
×6

Asked: 26 Jul '17, 17:55

Seen: 559 times

Last updated: 27 Jul '17, 17:54