Last active
June 2, 2019 22:22
-
-
Save karellism/1562b304a046c42ca00d to your computer and use it in GitHub Desktop.
Reading numeric values
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
// Demonstrates reading numeric values. | |
// From http://www.cs.utexas.edu/users/ndale/Scanner.html | |
// Class NumericInput demonstrates reading numeric values. | |
import java.util.Scanner; | |
import java.io.*; | |
public class NumericInput { | |
public static void main(String[] args) { | |
// Declarations | |
Scanner in = new Scanner(System.in); | |
int integer; | |
long longInteger; | |
float realNumber; | |
double doubleReal; | |
String string1; | |
String string2; | |
// Prompts | |
System.out.println("Enter an integer, a long integer, " + "a floating-point "); | |
System.out.println("number, another floating-point number, " + "and a string."); | |
System.out.println("Separate each with a blank or return."); | |
// Read in values | |
integer = in.nextInt(); | |
longInteger = in.nextLong(); | |
realNumber = in.nextFloat(); | |
doubleReal = in.nextDouble(); | |
string1 = in.nextLine(); | |
System.out.println("Now enter another value."); | |
string2 = in.next(); | |
System.out.println("Here is what you entered: "); | |
System.out.println(integer + " " + longInteger + " " + realNumber + " " + doubleReal + " " + string1 + " and " + string2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment