Check 2 digit positive number in Java
if else - Question 7
In this question, we will see how to check if a number is a two digit positive number or not in Java programming using the if else statement. To know more about if else statement click on the if else statement lesson.
Q7) Write a program in Java to input a number and check if it is a two digit positive number or not. All number starting from 10 to 99 are two digit positive numbers. Make use of logical operator && to solve this question.
Program
import java.util.Scanner;
public class Q7
{
public static void main(String args[])
{
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number ");
n=sc.nextInt();
if(n>=10 && n<100)
{
System.out.print("Two digit positive number");
}
else
{
System.out.print("Not two digit number");
}
}
}
Output
Enter a number 54 Two digit positive number