List of usage examples for java.util Scanner hasNext
public boolean hasNext()
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()); }/*from w w w. ja v 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); while (scanner.hasNext()) { if (scanner.hasNextShort()) { System.out.println("Found :" + scanner.nextShort(4)); }//from w w w . j av a 2 s . c o m 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 "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { if (scanner.hasNextInt()) { System.out.println("Found :" + scanner.nextInt()); }/*from www .ja v a 2s . com*/ 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"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is byte, print found and the byte if (scanner.hasNextByte()) { System.out.println("Found :" + scanner.nextByte()); }//from w w w . ja va 2 s. c o m 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 "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is a int, print found and the int with radix 4 if (scanner.hasNextInt()) { System.out.println("Found :" + scanner.nextInt(4)); }/*from ww w . j ava 2 s . 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"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is BigInteger, print "Found" and the Integer if (scanner.hasNextBigInteger()) { System.out.println("Found :" + scanner.nextBigInteger()); }/* w w w . j ava 2 s. co m*/ // if a BigInteger 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 1 + 1 = 2.0 true "; Long l = 123456789098765432L; s = s + l;//from w ww .j a v a 2 s .c o m Scanner scanner = new Scanner(s); while (scanner.hasNext()) { System.out.println("Not Found :" + scanner.next()); if (scanner.hasNextLong()) { System.out.println("Found :" + scanner.nextLong()); } } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "Hello true World! 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is boolean, print found and the boolean if (scanner.hasNextBoolean()) { System.out.println("Found :" + scanner.nextBoolean()); }//w ww. j a v a 2 s . c o m // if a boolean 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) throws Exception { Console cnsl = System.console(); if (cnsl != null) { System.out.print("Enter name : "); Scanner scan = new Scanner(cnsl.reader()); while (scan.hasNext()) { String str = scan.next(); System.out.println(str); }/*ww w. jav a 2 s. c om*/ } }
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 the next is BigDecimal, print found and the decimal if (scanner.hasNextBigDecimal()) { System.out.println("Found :" + scanner.nextBigDecimal()); }//from w w w. j a v a2 s . com // if a BigDecimal is not found, print "Not Found" and the token System.out.println("Not Found :" + scanner.next()); } scanner.close(); }