1.Write a program to check whether a given number is even
or odd.
if(a%2==0)
{
System.out.println(" even ");
}
else
{
System.out.println("odd");
}
output: even
2)2.Write a program to check whether a given character is an alphabet, digit, or special character
char b ='A';
{
switch (b)
case 'A':
System.out.println("alphebet");
break;
case '2':
System.out.println("digits");
break;
case '&':
System.out.println("special char");
break;
default:
System.out.println("decimal values");
}
output:alphebet
3.Write a program to check whether a given character is a vowel or consonant
char c ='e';
{
switch (c)
case 'a','e','i','o','u':
System.out.println("vowels");
break;
default:
System.out.println("consonent");
}
output:vowels
Top comments (0)