Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

scanner check if int

boolean isAnInt = scanner.hasNextInt();
Comment

java to check if its a number scanner

Scanner sc = new Scanner(System.in);
int number;
do {
    System.out.println("Please enter a positive number!");
    while (!sc.hasNextInt()) {
        System.out.println("That's not a number!");
        sc.next(); // this is important!
    }
    number = sc.nextInt();
} while (number <= 0);
System.out.println("Thank you! Got " + number);
Comment

PREVIOUS NEXT
Code Example
Java :: java get date in utc 
Java :: array contains java 
Java :: Java for Keyword 
Java :: mobile number validation to edittext in android 
Java :: replace substring at index java 
Java :: Java make numbers 
Java :: java triangle 
Java :: java list distinct by key 
Java :: on touch listener android 
Java :: printing arraylist 
Java :: from string to double java 
Java :: java exception message 
Java :: how to print an array in java 
Java :: explicit casting 
Java :: how to set radio button checked in android programmatically 
Java :: operador ternario java 
Java :: How to efficiently find the next greater permutation of a list of values, in Java? 
Java :: integer to string java 
Java :: How to find the prime factors of a number in Java? 
Java :: Processing Java examples 
Java :: java for each loop 
Java :: count occurrences of character in string java 8 
Java :: sudoku solver 
Java :: testing the web layer without authentication spring 
Java :: java delete column from csv 
Java :: java initialize string array 
Java :: convert double into integer 
Java :: java string to integer 
Java :: set textview text android java 
Java :: java logger with different colors 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =