Java programs
Using scanner class
10.)Write a program to input an integer and check whether it is a 2-digit or a 3-digit number or not. Incase.
it is not a 2-digit or a 3-digit number, a relevant message ("Not 2 or 3 digit number") should be displayed.
Answers
Answered by
0
Explanation:
While input, use string datatype. Calculate that datatype's length using length(); function and display the message according the length
Answered by
3
Answer:
class Q10
{
95 Computer Applications – IX (ICSE Course) Answers
static void main()
{
int n;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter an integer:”);
n=sc.nextInt();
if(n>=10 && n<=99 || n>=-99 && n<=-10)
System.out.println(“2-digit number”);
else if(n>=100 && n<=999 || n>=-999 && n<=-100)
System.out.println(“3-digit number”);
else
System.out.println(“Not a 2 or 3-digit number”);
}
}
Explanation:
Similar questions