List of usage examples for java.util Scanner close
public void close()
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); // use US locale in order to be able to identify shorts in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a short System.out.println(scanner.hasNextShort()); System.out.println(scanner.next()); }//from w w w . ja v a 2s. c o m scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com \n 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); // print the next line System.out.println(scanner.nextLine()); // check if there is a next line again System.out.println(scanner.hasNextLine()); System.out.println(scanner.nextLine()); // check if there is a next line again System.out.println(scanner.hasNextLine()); scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com "; Long l = 1234567890987654L;//from w w w .j a va 2 s . c o m s = s + l; Scanner scanner = new Scanner(s); // use US locale in order to be able to identify long in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a long with radix 4 System.out.println(scanner.hasNextLong(4)); System.out.println(scanner.next()); } scanner.close(); }
From source file:com.envirover.spl.SPLGroundControl.java
public static void main(String[] args) { try {/*from w ww .j a v a 2s. c o m*/ SPLDaemon daemon = new SPLDaemon(); daemon.init(new SPLDaemonContext(args)); daemon.start(); System.out.println("Enter 'stop' to exit the program."); Scanner scanner = new Scanner(System.in); String str; while (!(str = scanner.next()).equalsIgnoreCase("stop")) { //Just echo the user input for now. System.out.println(str); } System.out.println("Exiting..."); scanner.close(); daemon.stop(); daemon.destroy(); System.out.println("Done."); System.exit(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:Main.java
public static void main(String[] args) { String s = "Hello true World! 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is boolean, print found and the boolean if (scanner.hasNextBoolean()) { System.out.println("Found :" + scanner.nextBoolean()); }/*w w w. j ava 2s. c o m*/ // if a boolean is not found, print "Not Found" and the token System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is byte with radix 7, print found and the byte if (scanner.hasNextByte()) { System.out.println("Found :" + scanner.nextByte(7)); }// w w w . j ava 2 s . c o m // if a Byte is not found, print "Not Found" and the token System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is BigInteger, print "Found" and the Integer if (scanner.hasNextBigInteger()) { System.out.println("Found :" + scanner.nextBigInteger()); }/*from w w w. j a v a2 s. c o m*/ // if a BigInteger is not found, print "Not Found" and the token System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is BigDecimal, print found and the decimal if (scanner.hasNextBigDecimal()) { System.out.println("Found :" + scanner.nextBigDecimal()); }//from ww w . j av a2s .c o m // if a BigDecimal is not found, print "Not Found" and the token System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0"; Scanner scanner = new Scanner(s); // find a pattern of 2 letters before com, with horizon of 5 System.out.println(scanner.findWithinHorizon(Pattern.compile("..com"), 5)); // find a pattern of 2 letters before com, with horizon of 10 System.out.println(scanner.findWithinHorizon(Pattern.compile("..com"), 10)); // print the rest of the string System.out.println(scanner.nextLine()); scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Scanner scanner = new Scanner(s); System.out.println(scanner.nextLine()); // change the locale of this scanner scanner.useLocale(Locale.US); // change the radix of this scanner scanner.useRadix(30);/*w w w . ja v a 2s .co m*/ // reset and check the values for radix and locale, which are the default scanner.reset(); System.out.println(scanner.radix()); System.out.println(scanner.locale()); scanner.close(); }