Question:
How do you read a double from a scanner?
Answer:
Use the methed Scanner.nextDouble().
Code:
import java.util.Scanner; public class ScanDouble { public static void main(String[] args) { System.out.print("Enter double: " ); Scanner in=new Scanner(System.in); double d=in.nextDouble(); System.out.println("You entered: " + d); } }
Output:
$ java ScanDouble Enter double: 12.2 You entered: 12.2