Write a program in Java to enter the string. Count and display:
The character with lowest ASCII code in lower case
The character with highest ASCII code in lower case
The character with lowest ASCII code in upper case
The character with highest ASCII code in upper case
Sample Output:
The character with lowest ASCII code in lower case: a
The character with highest ASCII code in lower case: y
The character with lowest ASCII code in upper case: E
The character with highest ASCII code in upper case: P
Solution:
import ISjava.util.Scanner;
class lowhighascii
{
public static void main(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence:");
String s = sc.nextLine();
int p=0,q=999,r=0,t=999;
for(int i=0;i<s.length();i++)
{
char ch = s.charAt(i);
if(Character.isUpperCase(ch))
{
p=Math.max(p,(int)ch);
q=Math.min(q,(int)ch);
}
else if(Character.isLowerCase(ch)){
r=Math.max(r,(int)ch);
t=Math.min(t,(int)ch);
}
}
System.out.println("The character with lowest ASCII code in lower case:"+(char)t);
System.out.println("The character with highest ASCII code in lower case:"+(char)r);
System.out.println("The character with lowest ASCII code in upper case:"+(char)q);
System.out.println("The character with highest ASCII code in upper case:"+(char)p);
}
}