List of usage examples for java.util Scanner nextInt
public int nextInt(int radix)
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 w w w . j a va 2 s.com*/ System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:com.siphyc.utils.Utilities.java
public static boolean isInteger(String s, int radix) { Scanner sc = new Scanner(s.trim()); if (!sc.hasNextInt(radix)) { return false; }/* www .j ava 2 s .c om*/ // we know it starts with a valid int, now make sure // there's nothing left! sc.nextInt(radix); return !sc.hasNext(); }