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); scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a short with a radix 4 System.out.println(scanner.hasNextShort(4)); System.out.println(scanner.next()); }/* ww w . j a v a 2 s. co m*/ scanner.close(); }
From source file:Main.java
public static void main(String[] args) throws FileNotFoundException { Scanner scanner = new Scanner(new FileInputStream("c:/text.txt").getChannel(), StandardCharsets.UTF_8.name()); System.out.println(scanner.nextLine()); // change the radix of the scanner scanner.useRadix(32);/*from ww w . j ava 2 s . c om*/ // display the new radix System.out.println(scanner.radix()); 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, print found and the byte if (scanner.hasNextByte()) { System.out.println("Found :" + scanner.nextByte()); }/* w w w . jav a 2 s . c om*/ 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); // check if the scanner has a token System.out.println(scanner.hasNext()); // print the rest of the string System.out.println(scanner.nextLine()); // check if the scanner has a token after printing the line System.out.println(scanner.hasNext()); 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); // check if the scanner's next token matches "c" System.out.println(scanner.hasNext("c")); // check if the scanner's next token matches "=" System.out.println(scanner.hasNext("=")); // 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); while (scanner.hasNext()) { // if the next is a int, print found and the int with radix 4 if (scanner.hasNextInt()) { System.out.println("Found :" + scanner.nextInt(4)); }// w ww. j a v a 2s .c o m System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 3.12345f"; Scanner scanner = new Scanner(s); // assign locale as US to recognize float numbers in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a float System.out.println(scanner.hasNextFloat()); System.out.println(scanner.next()); }//from ww w.jav a 2 s. co m scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 1.3985"; Scanner scanner = new Scanner(s); // assign locale as US to recognize double numbers in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a double System.out.println(scanner.hasNextDouble()); System.out.println(scanner.next()); }//from ww w . ja va 2 s. c o m scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com "; Long l = 1234567890987654L;/*w w w. j av a 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 along System.out.println(scanner.hasNextLong()); System.out.println(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 string of world, with horizon of 10 System.out.println(scanner.findWithinHorizon("com", 10)); // find a string of world, with horizon of 20 System.out.println(scanner.findWithinHorizon("=", 20)); // print the rest of the string System.out.println(scanner.nextLine()); scanner.close(); }