List of usage examples for java.util Scanner hasNextInt
public boolean hasNextInt(int radix)
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()); }// w w w.j a va 2s . c o m 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; }/*from www . j a v a 2 s. com*/ // we know it starts with a valid int, now make sure // there's nothing left! sc.nextInt(radix); return !sc.hasNext(); }