Example usage for java.util Scanner Scanner

List of usage examples for java.util Scanner Scanner

Introduction

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

Prototype

public Scanner(ReadableByteChannel source) 

Source Link

Document

Constructs a new Scanner that produces values scanned from the specified channel.

Usage

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 next token matches the pattern and print it
    System.out.println(scanner.next("java2s"));

    // check if next token matches the pattern and print it
    System.out.println(scanner.next("="));

    scanner.close();//from w  w  w  .  j a  va  2 s . com
}

From source file:Main.java

public static void main(String[] args) {

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

    Scanner scanner = new Scanner(s);

    // print the line
    System.out.println(scanner.nextLine());

    // print the current locale
    System.out.println(scanner.locale());

    scanner.close();//w ww  .  ja  va 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 an int with a radix of 4
        System.out.println(scanner.hasNextInt(4));

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

    // find the next token and print it
    System.out.println(scanner.next());

    // find the next token and print it
    System.out.println(scanner.next());

    scanner.close();/*w ww .j a v a  2s.  c  om*/
}

From source file:Main.java

public static void main(String[] args) {

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

    Scanner scanner = new Scanner(s);

    // print the line
    System.out.println(scanner.nextLine());

    // check if there is an IO exception
    System.out.println(scanner.ioException());

    scanner.close();/*from  w w  w  .ja  va  2  s  . c om*/
}

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
        System.out.println(scanner.hasNextInt());

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

    Scanner scanner = new Scanner(s);

    scanner.skip("java2s");

    System.out.println(scanner.nextLine());

    scanner.close();//w  ww .j a  v 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());

    System.out.println("" + scanner.toString());

    scanner.close();/*from  ww  w .  ja v a 2s  .c o 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());

    // attempt to call remove results in an exception
    scanner.remove();/*from w ww .j av a  2s  . 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 ";

    Scanner scanner = new Scanner(s);

    System.out.println(scanner.nextLine());

    // print the default radix
    System.out.println(scanner.radix());

    scanner.close();// w  ww.j  a  va2  s.  c  om
}