Computer Science, asked by Anonymous, 22 hours ago

To read a number and find out whether the number has two digits or one digit. Hint: Number greater or equal to 10 is two digits number.​

Answers

Answered by samarthkrv
2

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 Scanner sc = new Scanner(System.in);

 System.out.print("Enter a number:");

 int num = sc.nextInt();

     if(num >= 10 && num <= 99){

         System.out.println(num + " is a two digit number");

     }

     else{

         System.out.println(num + " is a one digit number");

     }

}

}

Explanation:

Answered by Shivu516
0

This program only tells if the inputted number is a two-digit or one-digit number

This program is in Java

import java.util.Scanner;

public class Digit_Teller{

   public static void main(String [] args){

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter a number to know if it's a one-digit or two-digit number: ");

       double num = sc.nextDouble();

       if (num >= 10 && num < 100){

           System.out.println("It's a two-digit number");

       }

       else if (num >= 100){

           System.out.println("This number has more than two digits");

       }

       else {

           System.out.println("This is a one-digit number");

       }

   }

}

Output:

The underlined values are the inputs

(i)

Enter a number to know if it's a one-digit or two-digit number: 96

It's a two-digit number

(ii)

Enter a number to know if it's a one-digit or two-digit number: 2006

This number has more than two digits

(iii)

Enter a number to know if it's a one-digit or two-digit number: 6

This is a one-digit number

Hope you liked the answer ˶ᵔ ᵕ ᵔ˶

Similar questions