Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d9abcad

Browse files
Shows use of the of Scanner class nextLine()
Reads a character string from the user and prints it.
1 parent 235e61f commit d9abcad

File tree

1 file changed

+20
-0
lines changed
  • textbook work/java software solutions/2. Data and Expressions

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//********************************************************************
2+
// Echo.java Author: Lewis/Loftus
3+
//
4+
// Demonstrates the use of the nextLine method of the Scanner class
5+
// to read a string from the user.
6+
//********************************************************************
7+
import java.util.Scanner;
8+
9+
public class Echo {
10+
//-----------------------------------------------------------------
11+
// Reads a character string from the user and prints it.
12+
//-----------------------------------------------------------------
13+
public static void main(String[] args){
14+
String message;
15+
Scanner scan = new Scanner(System.in);
16+
System.out.println("Enter a line of text:");
17+
message = scan.nextLine();
18+
System.out.println("You entered: \"" + message + "\"");
19+
}
20+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /