Assignment 2
Write a Java program to input an integer from the user. Check and display the number
input is a two digit number, a three-digit number or a four digit number, else display
"number not in range".
Input: 200
Output: It is a three-digit number
Answers
Answered by
0
Answer:
import java.util.* ;
class Example
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int n,l;
String str1,str;
System.out.println("Enter A Number");
n=sc.nextInt();
str1=n.toString();
str=str.trim();
l=str.length();
if(l==2)
System.out.println( "It is a two digit number");
else
if(l==3)
System.out.println("It is a three digit number");
else
if(l==4)
System.out.println("It is a four digit number");
else
System.out.println("Number not in range");
}
}
I hope my answer was helpful for you. If you want any explanation regarding this answer you can ask me.
Similar questions