Hi,
I'm new to Java and I have a homework assignment where I'm unable to do this code.
Q.)Write a program called RectanglePattern.java with a main method. The program prompts for the height and width of a rectangle (you can assume that the user always enters a positive number), and prints out the corresponding number rectangle as shown in the sample run.
Sample run of the program:
Enter the width of the rectangle: 5
Enter the height of the rectangle: 4
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
So far I have this:
import java.util.Scanner;
public class RectanglePattern {
public static void main (String [] args) {
Scanner sc = new Scanner (System.in);
System.out.print ("Enter the width of the rectangle : ");
int width = sc.nextInt();
System.out.print ("Enter the height of the rectangle : ");
int height = sc.nextInt();
for (int i = 1; i<=width; i++) {
System.out.print ("1 ");
}
System.out.println (" ");
for (int j = 1; j <=height; j++) {
System.out.println ("2 ");
}
}
}
I figure there has to be a nested loop somewhere here, but I can't figure how.
--- Update ---
bump! (10char)