/** This class shows how to read user input from the command line using Scanner class: java.util.Scanner Refer to API docs for specifics. */ import java.util.Scanner; public class ReadScanner { public static void main(String[] args) { // first you need to create a Scanner object and attach it to System.in Scanner in = new Scanner(System.in); System.out.print("Enter a sentence: "); String line = in.nextLine(); System.out.println("You entered: " + line + "\n"); System.out.print("Enter another sentence (only the first word will be read): " ); String word = in.next(); System.out.println("You entered: " + word + "\n"); // if user entered more than one word ignore words after the first String temp = in.nextLine(); System.out.print("Enter a number: " ); int num = in.nextInt(); System.out.println("You entered: " + Integer.toString(num) + "\n\n"); } }