Please help me in writing a Program that takes a single digit or value from user and then prints whether the value is an Alphabet or a number or a special character. And if the input is alphabet then determines whether its vowel or not. I don’t Know how to use the Builtin Java functions coz am new to java. Below is the code.
import java.util.Scanner;
public class myClass {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("Enter The Value To Check: ");
int N=input.nextInt();
for(int i=0; i<=9; i++){
if(N==i) {
System.out.println("You Entered A Number");
break;
}
}
if(N=='a'||N=='A' ||N=='z' ||N=='Z') {
System.out.println("You Entered An Alphabet");
}
for(int k=128; k<=255; k++){
if (N==k){
System.out.println("You Enter A Special Character");
}
}
}
}
You seem to be confusing ASCII with ASCII encoded decimals… nextInt() returns next integer, which won’t work if you enter say ?, &, * etc. Use the hasNext() method to check what’s available first