Java Scanner read double from console

Description

Java Scanner read double from console


import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner keyboard = new Scanner(System.in);

    System.out.println("How old are you? ");
    int age = keyboard.nextInt();

    System.out.println("How many feet tall are you? ");
    String heightFt = keyboard.next();

    System.out.println("How many inches tall are you? ");
    String heightIn = keyboard.next();

    System.out.println("How much do you weight? ");
    double weight = keyboard.nextDouble();

    System.out.println("So you are " + age + " old, " + heightFt + heightIn + " tall and " + weight + " heavy.");
    keyboard.close();/*w w  w. j a v  a 2s .  c o m*/
  }
}



PreviousNext

Related