Java program to read a double value
Program Description
Write a java program to read a double value from the user input. We will make use of .nextDouble() method of the Scanner class to read the double value into the program.
Java Program
import java.util.Scanner; /************************************************** * InputDoubleDemo.java * @program : Program to take double value as input. * @web : www.TestingDocs.com * @version : 1.0 **************************************************/ public class InputDoubleDemo { public static void main(String[] args) { // scanner object variable used in the program Scanner keyboard = new Scanner(System.in); double userInput;// to hold user input System.out.println("Enter double value as input:="); userInput = keyboard.nextDouble(); System.out.println("The double value user entered is :=" + userInput); } }
Program Output
Enter double value as input:=
3.14
The double value user entered is :=3.14
Screenshot