define token based input in java code example
Example 1: Don't use a line-beased input after a token-based input.
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int value = input.nextInt();
System.out.println("The value is " + value);
System.out.print("Enter a line: ");
String line = input.nextLine();
System.out.println("The line is " + line);
}
}
Example 2: Don't use a line-beased input after a token-based input.
Enter a phone word: warbler
The number is 9272537.
Enter a phone word: GOOD4U2
The number is 4663482.
Enter a phone word: OMG
Your phone word is not long enough for a phone number.
Enter a phone word: GREAT DEALS
The number is 4732833.