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 define empty string list 
Java :: select word from array 
Java :: expected exception junit 
Java :: how to crate an array of integers in java 
Java :: turn ascii into text javascriot 
Java :: java charsequence to string 
Java :: Fibonacci Series Program. in java 
Java :: java sort list of strings 
Java :: how to divide two ints and get a double java 
Java :: reverse string using recursion java with explanation 
Java :: how to create a circle in java 
Java :: get absolute path from relative java 
Java :: android recyclerview show hide item with animation with default animation 
Java :: set intersection java 
Java :: char array to arraylist java 
Java :: android date time 
Java :: priority queue java comparator lambda 
Java :: copy to clipboard android studio 
Java :: initialize arraylist in 1 line in java 
Java :: how to convert epoch time to date in java 
Java :: java copy array 
Java :: association in java 
Java :: java get year 
Java :: java home mac 
Java :: java random number between 2 values inclusive 
Java :: odd number in java 
Java :: java list distinct by object attribute 
Java :: can strings be used in a 2 dimensional array in java 
Java :: split method in java 
Java :: java date format with timezone 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =