import java.util.Scanner; public class ReadDoubleInput { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a double value: "); double value = scanner.nextDouble(); System.out.println("You entered: " + value); } }
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReadDoubleFile { public static void main(String[] args) { File inputFile = new File("input.txt"); try { Scanner scanner = new Scanner(inputFile); double value = scanner.nextDouble(); System.out.println("The first value in the file is: " + value); } catch (FileNotFoundException e) { System.out.println("File not found: " + inputFile.getName()); } } }This example reads a double value from a file called "input.txt" using the nextDouble() method. The try-catch block is used to catch any FileNotFoundException that may occur.