Respuesta :
Answer:
// program in java.
// package
import java.util.*;
// class definition
class SquareDisplay
{
// main method of the class
public static void main (String[] args) throws java.lang.Exception
{
try{
// variable
int num;
// scanner object to read input
Scanner scr=new Scanner(System.in);
System.out.print("Enter an integer in the range of 1-15:");
// read integer from user
num=scr.nextInt();
// read until input is not in range 1-15
while(num<0 || num>15)
{
System.out.print("wrong input!!enter again:");
// read again
num=scr.nextInt();
}
// print square of X
for(int a=1;a<=num;a++)
{
for(int b=1;b<=num;b++)
{
System.out.print("X");
}
System.out.println();
}
}catch(Exception ex){
return;}
}
}
Explanation:
Read an integer from user and assign it to variable "num".Check if input is not in range 1-15 then ask again until user enter a number between 1-15 only.Then print a square of character "X" with the help of two nested for loops.
Output:
Enter an integer in the range of 1-15:-4
wrong input!!enter again:20
wrong input!!enter again:4
XXXX
XXXX
XXXX
XXXX