Scanner1.java
Select all
/* Scanner1.java David G. Klick CIS 260 2005-01-17 Demonstrates use of Scanner class and static import of java.lang.System.out */ import static java.lang.System.out; import java.io.*; import java.util.Scanner; public class Scanner1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = 0; out.print("Enter an integer: "); while (!sc.hasNextInt()) { out.print("Try again!\nEnter an integer: "); sc.next(); } n = sc.nextInt(); out.println("I read in: " + n); } }