Skip to content

Instantly share code, notes, and snippets.

@andymuncey
Created October 21, 2021 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymuncey/89b7dac951ff1baeb84fe525651565df to your computer and use it in GitHub Desktop.
Save andymuncey/89b7dac951ff1baeb84fe525651565df to your computer and use it in GitHub Desktop.
Getting numbers using the Scanner
//first part - getting an integer from the user and printing it
System.out.println("Please type an integer followed by enter:");
Scanner inputScanner = new Scanner(System.in);
int userInteger = inputScanner.nextInt();
inputScanner.nextLine();
System.out.println("Your integer is " + userInteger);
//second part - getting a double from the user
System.out.println("Please type an double (a number with a decimal point) followed by enter:");
double userDouble = inputScanner.nextDouble();
inputScanner.nextLine();
System.out.println("Your double is " + userDouble);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment