-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputTest.java~
More file actions
27 lines (21 loc) · 772 Bytes
/
Copy pathInputTest.java~
File metadata and controls
27 lines (21 loc) · 772 Bytes
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
//InputTest.java
//Shows how to use the scanner class and a variable for input
import java.util.Scanner;
class InputTest {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("What is your name?");
String userName = input.next();
System.out.println("Hi there, " + userName + "!");
} // end main
} // end class def
/*
Notes:
Import the Scanner class from java utility package
Create an instance called input.
Scanner needs to know where input will be coming from (file, console)
System.in refers to console
String is a text variable.
input.next returns the next String token (usually a word)
Plus sign is overloaded - in this case it's concatenating, not adding
*/