import java.util.Scanner;
public class String3
{
public static void main ( String [] args )
{
Scanner keyboard = new Scanner( System.in );
String word1, word2, restOfLine;
word1 = new String("");
word2 = new String("");
word3 = new String("");
restOfLine = new String("");
// ask for input from the keyboard
System.out.print("Enter a line: ");
// grab the first "word"
word1 = keyboard.next();
// grab the second "word"
word2 = keyboard.next();
// read the rest of the line
restOfLine = keyboard.nextLine();
// output the strings
System.out.println("word1 = " + word1);
System.out.println("word2 = " + word2);
System.out.println("restOfLine = " + restOfLine);
}
}
Back to Lesson 2 Examples
Back to Java Main Page