I have applied a check for not allowing alphabets.But its not working.....
Posted
by bhavna raghuvanshi
on Stack Overflow
See other posts from Stack Overflow
or by bhavna raghuvanshi
Published on 2010-06-18T05:23:54Z
Indexed on
2010/06/18
5:33 UTC
Read the original article
Hit count: 261
java
import java.util.Scanner;
public class Main extends Hashmap{
public static void main(String[] args) {
Hashmap hm = new Hashmap();
int x=0;
Scanner input = new Scanner(System.in);
do{
System.out.print("Enter any integer value between 1 to 12: ");
x = input.nextInt();
}while(x<=0 || x>12);
Scanner sc = new Scanner(System.in);
//int number;
do {
while (!sc.hasNextInt())
{
System.out.println("That's not a number!");
sc.next();
}
x = sc.nextInt();
}while(x>=0);
String month = hm.getEntry(x);
System.out.println(month);
}
}
here I need to restrict user from entering an alphabet.But its not working. pls help...
© Stack Overflow or respective owner