You are to write a short program that will input a positive integer numbers in t
ID: 3630522 • Letter: Y
Question
You are to write a short program that will input a positive integer numbers in the range 1 - 10. If the input numbers are not in the correct range a message should be sent to the user. Error messages are sent until correct input is submitted. Correct input numbers are used to print a rectangle which has sides named length and width. The printed rectangle is made up of an input character. After the figure is printed you are to ask the user if another rectangle is to be printed. Note that the input to the request for another rectangle is insensitive to case.
Enter length and width values (!= 0) for a filled rectangle.
Enter the length of the rectangle (+1 to +10): -8
Input Error -----
Enter the length of the rectangle (+1 to +10): 8
Enter the width of the rectangle (+1 to +10): 0
Input Error -----
Enter the width of the rectangle (+1 to +10): 4
Enter the symbol to be used: X
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
Do you want another rectangle, Yes or No: yes
Enter the length of the rectangle (+1 to +10): 1
Enter the width of the rectangle (+1 to +10): 1
Enter the symbol to be used: A
A
Do you want another rectangle, Yes or No: no
program to be written in java. I use netbeans
Explanation / Answer
import java.util.*;
public class Matrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = 0;
int y = 0;
String str;
String quit = " ";
while (!quit.equals("no")){
System.out.print("Enter the length of the rectangle (+1 to +10): ");
x = sc.nextInt();
while (x < 1 || x > 10){
System.out.println("Input Error -----");
System.out.print("Enter the length of the rectangle (+1 to +10): ");
x = sc.nextInt();
}
System.out.print("Enter the width of the rectangle (+1 to +10): ");
y = sc.nextInt();
while (y < 1 || y > 10){
System.out.println("Input Error -----");
System.out.print("Enter the width of the rectangle (+1 to +10): ");
y = sc.nextInt();
}
System.out.print("Enter the symbol to be used: ");
str = sc.next();
for (int county=0; county < y; county++ ){
for (int countx=0; countx < x; countx++)
{
System.out.print(str);
}
System.out.println();
}
System.out.println("Do you want another rectangle, Yes or No: ");
quit = sc.next();
quit = quit.toLowerCase();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.