Example usage for java.util Scanner hasNext

List of usage examples for java.util Scanner hasNext

Introduction

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

Prototype

public boolean hasNext() 

Source Link

Document

Returns true if this scanner has another token in its input.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    String instr = "10 99.88 scanning is easy.";
    Scanner conin = new Scanner(instr);

    while (conin.hasNext()) {
        if (conin.hasNextDouble()) {
            System.out.println(conin.nextDouble());
        }//ww  w . j a  v a  2 s.c o m
    }

}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0";

    Scanner scanner = new Scanner(s);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a BigInteger
        System.out.println(scanner.hasNextBigInteger());
        System.out.println(scanner.next());
    }/*from  w w  w  . j  a  v  a 2  s . c o m*/
    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);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a BigInteger with radix 5
        System.out.println(scanner.hasNextBigInteger(4));

        System.out.println(scanner.next());
    }/*  w  ww . ja v  a2 s  .  co m*/
    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 (scanner.hasNextShort()) {
            System.out.println("Found :" + scanner.nextShort());
        }/*from ww w. java2s.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 true 9000000000000000000000L";

    Scanner scanner = new Scanner(s);

    while (scanner.hasNext()) {
        System.out.println("Not Found :" + scanner.next());
        if (scanner.hasNextLong()) {
            System.out.println("Found :" + scanner.nextLong(20));
        }//from w  ww  .j  a  v a 2  s. c o  m
    }
    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);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a byte with radix 4
        System.out.println(scanner.hasNextByte(4));

        System.out.println(scanner.next());
    }//from ww  w . j a  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 ";

    Scanner scanner = new Scanner(s);

    while (scanner.hasNext()) {
        // check if the scanner's next token is an int with a radix of 4
        System.out.println(scanner.hasNextInt(4));

        System.out.println(scanner.next());
    }/*from   w w w .j a va 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";

    Scanner scanner = new Scanner(s);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a BigDecimal
        System.out.println(scanner.hasNextBigDecimal());

        System.out.println(scanner.next());
    }/*from   ww w  .j a v a 2  s .  co  m*/
    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com false 1 + 1 = 2.0";

    Scanner scanner = new Scanner(s);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a boolean
        System.out.println(scanner.hasNextBoolean());

        System.out.println(scanner.next());
    }// w  ww  . java2s. c  o  m
    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);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a byte
        System.out.println(scanner.hasNextByte());

        System.out.println(scanner.next());
    }//w  ww.  j a v  a 2  s.co m
    scanner.close();
}