If we are required to check whether or not, the data entered by the user is of the double type, we can make use of the hasNextDouble method here. This method returns true, if the data input by the user is of type double, and otherwise, the method returns false.
Checking if the user input is double type(hasNextDouble method)
Lets have a look at a sample program, through which, we demonstrate the hasNextDouble method →
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean storesdouble = scanner.hasNextDouble();
System.out.println(storesdouble);
}
}
So, if you try to implement the above program and give some double type input, the method is going to return true, else it is going to return false.