import java.util.Scanner; public class loops { public static void main(String[] args) { int length; int width; int count = 0; Scanner input = new Scanner (System.in); System.out.print("Enter the length: "); length = input.nextInt(); while (length<=0 || length >=21 ) { System.out.print("Invalid – enter length between 1 and 20:"); System.out.print("\nEnter the length: "); length = input.nextInt(); } System.out.print("Enter the width: "); width = input.nextInt(); while (width<=0 || width >=21 ) { System.out.print("Invalid – enter width between 1 and 20:"); System.out.print("\nEnter the width: "); width = input.nextInt(); if (width>=1 || width <=20){ while (count<width){ System.out.print("*"); count++;} } } while (count<length){ System.out.print("\n*" + width); count++;} } }
Hi how do i solve this. to make my answer equal to the length and width I inputted.
example:
Enter the length: 6
Enter the width: 4
****
****
****
****
****
****
I always get the length right, but I can't make the width working