-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathScannerDemo.java
More file actions
28 lines (26 loc) · 1.03 KB
/
ScannerDemo.java
File metadata and controls
28 lines (26 loc) · 1.03 KB
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
import java.io.File;
import java.util.Scanner;
public class ScannerDemo {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in); // Keyboard
// Scanner scanner = new Scanner(new
// File("/Users/amitsrivastava/Documents/dsa-june/strings/ReverseWords.java"));
// while (scanner.hasNextLine()) {
// System.out.println(scanner.nextLine()); // \n new line
// }
// while (scanner.hasNext()) {
// System.out.println(scanner.next()); // space
// }
System.out.println("Enter the Age");
int age = scanner.nextInt(); // 21 \n
System.out.println("Enter the Name");
scanner.nextLine();
String name = scanner.nextLine(); // \n
System.out.println("Age " + age + " Name " + name);
Scanner s = new Scanner(System.in);
System.out.println("Enter the City");
System.out.println(s.next());
s.close(); // close at end
scanner.close(); // close System.in
}
}