List of usage examples for java.util Scanner hasNextFloat
public boolean hasNextFloat()
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Float f = 1.2385f;//from ww w . ja v a 2 s.co m 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 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()); }// www . j a v a 2 s. c o m scanner.close(); }