List of usage examples for java.util Scanner useLocale
public Scanner useLocale(Locale locale)
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()); }/*w ww .ja v a2s . c o m*/ scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Float f = 1.2385f;/*w w w .ja v a 2s.c om*/ s = s + f; Scanner scanner = new Scanner(s); scanner.useLocale(Locale.US); while (scanner.hasNext()) { scanner.next(); if (scanner.hasNextFloat()) { System.out.println("Found :" + scanner.nextFloat()); } } 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); scanner.useLocale(Locale.US); while (scanner.hasNext()) { // if the next is a double, print found and the double if (scanner.hasNextDouble()) { System.out.println("Found :" + scanner.nextDouble()); }/*www . j ava 2 s. c om*/ // if a double 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 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 www .ja v a 2 s. c om 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. j av a2s .c o m scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com "; Long l = 1234567890987654L;/*from w ww .java2s .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 "; Long l = 1234567890987654L;//from ww w. jav a2 s .co 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: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.j a va 2 s. com*/ 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 the scanner scanner.useLocale(Locale.ENGLISH); // display the new locale System.out.println(scanner.locale()); scanner.close();// www. jav a 2 s . co m }
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 ww.j a v a 2 s .c o 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(); }