Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package rectangle;
  2. //import the scanner to ask the user for values
  3. import java.util.Scanner;
  4.  
  5. public class rectangle {
  6.  
  7. public static void main(String[] args) {
  8. // Shervin Tangestanian
  9. // rectangles
  10. int x1 = 1, x2 = 1, w, l;//x2 is a counter for the vertical value and x1 is for the horizontal
  11.  
  12. Scanner scanner = new Scanner(System.in);
  13. System.out.println("Please enter the width of the rectangle: ");//Prompt the user for length and width and assign those values
  14. w = scanner.nextInt();
  15. System.out.println("Please enter the length of the rectangle: ");
  16. l = scanner.nextInt();
  17. System.out.println("Here is your rectangle");
  18. while (x2 <= l) {//while the vertical component is less or equal to the length entered the following code will loop
  19. System.out.println();//go to a new line
  20. x2++;//increase the value of x2 by 1
  21. do {
  22. System.out.print("*");//Keep printing * and adding 1 to x1 until x1 is equal to w
  23. x1++;
  24.  
  25. } while (x1 <= w);
  26. x1 = 1;
  27.  
  28. }
  29. System.out.println();
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement