-
-
Save andymuncey/89b7dac951ff1baeb84fe525651565df to your computer and use it in GitHub Desktop.
Getting numbers using the Scanner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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