Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rectangle;
- //import the scanner to ask the user for values
- import java.util.Scanner;
- public class rectangle {
- public static void main(String[] args) {
- // Shervin Tangestanian
- // rectangles
- int x1 = 1, x2 = 1, w, l;//x2 is a counter for the vertical value and x1 is for the horizontal
- Scanner scanner = new Scanner(System.in);
- System.out.println("Please enter the width of the rectangle: ");//Prompt the user for length and width and assign those values
- w = scanner.nextInt();
- System.out.println("Please enter the length of the rectangle: ");
- l = scanner.nextInt();
- System.out.println("Here is your rectangle");
- while (x2 <= l) {//while the vertical component is less or equal to the length entered the following code will loop
- System.out.println();//go to a new line
- x2++;//increase the value of x2 by 1
- do {
- System.out.print("*");//Keep printing * and adding 1 to x1 until x1 is equal to w
- x1++;
- } while (x1 <= w);
- x1 = 1;
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement