Could you help why my code Does not work?
public class Solution {
public static void main(String[] args) throws Exception {
Scanner sc1 = new Scanner(System.in);
int z;
int x = sc1.nextInt();
int y = sc1.nextInt();
int w = x*y;
for (z = 1; z<=2; z++)
{
for (z = 1; z<=4; z++)
System.out.print(w);
{
System.out.println();
}
}
}
}
Drawing a rectangle
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Anthony Chalk
12 December 2019, 09:50
Firstly, when you use nextInt(), it doesn't automatically read the next line, you'll have to use a nextLine() command in between x and y.
Secondly, don't multiply x and y together, that does nothing.
Thirdly, this your loop is displaying a 2 by 4 rectangle - that was the example given in the task conditions where m =2 and n=4, you need to display an m by n (or in your case, x by y) rectangle of 8.
Lastly, change
to
0