Take A Number From User And Check Whether It's Double Or Not | Java Programs

Output:

*** Check Whether Any Number Is Double Or Not ***

Enter any number: 930475
It's not a double number
-------------------------------------------------
*** Check Whether Any Number Is Double Or Not ***

Enter any number: 3452.56
It's a double number

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

public class TestIfNumIsDouble {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("*** Check Whether Any Number Is Double Or Not ***" + "\n");
        System.out.print("Enter any number: ");
        double number = scanner.nextDouble();
        if ((number % 1) == 0) {
            System.out.println("It's not a double number");
        } else {
            System.out.println("It's a double number");
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon