Computer Science, asked by killerstrikerawat, 9 months ago

Write a program in Java to enter a number using Scanner Class and check whether a number entered by the user is a single digit number, two digit number or a three digit number. If the number entered is a single digit number then check if the number is odd or even. If the number entered in a two digit number than check the number is more than 50 or not, and if the number entered in 3 digit number then check if the number is divisible by 5 or not. Sample input : 6 Sample output : Single digit number The number is even Sample input : 43 Sample output : Two digit number The number is less than 50 Sample input : 227 Sample output : Three digit number The number is not divisible by 5

Answers

Answered by BrainlyProgrammer
12

Answer:

Hi friend here is your answer

Coding for your question...

import java.util.*;

class Check

{

public static void main(String ar[])

{

Scanner sc= new Scanner (System.in);

System.out.println("Enter a no.");

int n=sc.nextInt();

if ((n>=0)&&(n<=9))

{

System.out.println("Single digit");

if (n%2==0)

System.out.println("Even");

else

System.out.println("odd");

}

else if ((n>9)&&(n<=99)

{

System.out.println("Double digit");

if (n<50)

System.out.println("Less than 50");

else

System.out.println("Greater than 50");

}

else if ((n>99)&&(n<=999))

{

System.out.println("Triple digit");

if (n%5==0)

{

System.out.println("Divisible by 5");

else

System.out.println("Not divisible by 5");

}

}

else System.out.println("Out of range");

}

}

}

Plz mark my answer brainliest

Answered by brainbean
2

import java.util.*;

public class program

{

   public static void main( )

   {

       Scanner sc= new Scanner(System.in);

       System.out.println("enter a number");

       int n= sc.nextInt( );

       int i, s=0, num=n;

       while(n>0)

       {

       i=n%10;

       s++;

       n=n/10;

       }  

       if(s==1) {

        if(num%2==0)

       System.out.println("even");

       else

       System.out.println("odd"); }

       else if(s==2)  

        { if(num>50)

       System.out.println("Greater than 50"); }

       else if(s==3)

        if(num%5==0) {

       System.out.println("divisible by 5")

      else

       System.out.println("not divisible by 5")}

}}

Similar questions