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
Answer:
The code to this question can be given as:
Code:
public interface Test //define interface
{
public abstract Duration getDuration(); //define method
getDuration.
public abstract Result check(int a);
//define method
check .
public abstract double getScore();
//define method getScore.
}
Explanation:
In the above code, we define an interface that is "Test" inside an interface, we define three methods that can be defined as:
- First, we define a method that is "getDuration" that method returns Duration as an object.
- Second, we define a method that is "check" this method accepts an integer parameter that is a and return Result.
- The third method is "getScore" this method will return a double value.
Answer: a. the number is: 14
Explanation:
i mean just try to write in 7 instead of x in the second line
then it would say the number is: ....
what is 7 times 2?
14
so the answer is a