public class Solution

{ public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String mS = reader.readLine(); String nS = reader.readLine(); int m = Integer.parseInt(mS); int n = Integer.parseInt(nS);

    for (int a = 1; a <= 2; a++){
        for (int b = 1; b < 4; b++){
            System.out.print(m * n);
        }
        System.out.println(m * n);

} } }

What is wrong with my code? It works well but i can't pass this task...

Here is the description

Write a program that reads from keyboard two numbers: m and n. The program should display to the screen a rectangle composed of eights sized m by n. Use “for” loop.

Example: m=2, n=4
8888
8888

asked 02 Aug '17, 17:39

adrs's gravatar image

adrs
32
accept rate: 0%


No, no, no! :D The size of rectangle depends on input! So you cannot use any number as termination in for loops. You dont need if statements.

link

answered 03 Aug '17, 02:17

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

I think you didnt understand your task. Your program has to draw rectangle composed of 8s

Example: input:

m=6, n=4

output:

 8888
 8888
 8888
 8888
 8888
 8888
link

answered 02 Aug '17, 17:55

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

edited 02 Aug '17, 17:56

Thanks for a reply, I thought now I understand it, but i still cant pass that task... Now i tried something like this:

public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String mS = reader.readLine(); String nS = reader.readLine(); int m = Integer.parseInt(mS); int n = Integer.parseInt(nS);

    for (int a = 0; a < 10; a++){
        if (a == m){
            break;
        }
        for (int b = 1; b < 10; b++){
            if (b == n){
                break;
            }
        System.out.print(8);
    }
    System.out.println(8);

    }

}

}

link

answered 02 Aug '17, 19:40

adrs's gravatar image

adrs
32
accept rate: 0%

edited 02 Aug '17, 19:41

Thanks for help, I did pass this task finally :) I think I was overthinking after hours of doing these exercises. Passed after first try today though.

link

answered 03 Aug '17, 04:01

adrs's gravatar image

adrs
32
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:

×36
×12
×3

Asked: 02 Aug '17, 17:39

Seen: 813 times

Last updated: 03 Aug '17, 04:01