-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinputs.java
34 lines (28 loc) · 1.08 KB
/
inputs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner; // Import the Scanner class
public class inputs {
public static void main(String args[]) {
// Variable declaration
String name;
int age;
// Create a Scanner object
Scanner myScanner = new Scanner(System.in);
System.out.print("Enter your name : ");
name = myScanner.nextLine(); // Read user input - String(with all white spaces)
System.out.print("Enter your age : ");
age = myScanner.nextInt(); // Read user input - Int
// Output user input
System.out.println(name);
System.out.println(age);
}
}
/*
Method Description
nextBoolean() Reads a boolean value from the user
nextByte() Reads a byte value from the user
nextDouble() Reads a double value from the user
nextFloat() Reads a float value from the user
nextInt() Reads a int value from the user
nextLine() Reads a String value from the user
nextLong() Reads a long value from the user
nextShort() Reads a short value from the user
*/