Example usage for java.util Scanner hasNextFloat

List of usage examples for java.util Scanner hasNextFloat

Introduction

In this page you can find the example usage for java.util Scanner hasNextFloat.

Prototype

public boolean hasNextFloat() 

Source Link

Document

Returns true if the next token in this scanner's input can be interpreted as a float value using the #nextFloat method.

Usage

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();
}