算法Sedgewick第四版-第1章基础-019一Scanner的用法
1 package algorithms.fundamentals001; 2 3 import java.util.Locale; 4 import java.util.Scanner; 5 6 import algorithms.util.StdIn; 7 8 public class IsEquals { 9 10 // assume Unicode UTF-8 encoding 11 private static final String CHARSET_NAME = "UTF-8"; 12 13 // assume language = English, country = US for consistency with System.out. 14 private static final Locale LOCALE = Locale.US; 15 16 private static Scanner scanner; 17 // do this once when StdIn is initialized 18 static { 19 resync(); 20 } 21 /** 22 * If StdIn changes, use this to reinitialize the scanner. 23 */ 24 private static void resync() { 25 setScanner(new Scanner(new java.io.BufferedInputStream(System.in), CHARSET_NAME)); 26 } 27 28 private static void setScanner(Scanner scanner) { 29 IsEquals.scanner = scanner; 30 IsEquals.scanner.useLocale(LOCALE); 31 } 32 33 public static void main(String[] args) { 34 // int a = scanner.nextInt(); 35 // int b = scanner.nextInt(); 36 // int c = scanner.nextInt(); 37 // System.out.println(a==b && b==c); 38 double a = scanner.nextDouble(); 39 double b = scanner.nextDouble(); 40 System.out.println((a > 0.0 && a < 1.0) && (b > 0.0 && b < 1.0)); 41 } 42 }
You can do anything you set your mind to, man!