Java Program to print Uppercase and Lowercase Character in a String . 20:41 Add Comment Edit Java program to find the uppercase and lowercase from a string : import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.io.*; public class Demo { public static void main(String args[]) throws Exception { // Write code here Scanner in = new Scanner(System.in); String str = in.nextLine(); char ch; int upperCase = 0, lowerCase = 0; for (int i = 0; i < str.length(); i++) { ch = str.charAt(i); int asciiValue = (int) ch; if (asciiValue >= 65 && asciiValue <= 90) { upperCase++; } else if (asciiValue >= 97 && asciiValue <= 122) { lowerCase++; } } System.out.println(upperCase); System.out.println(lowerCase); } } Share this:
0 comments:
Post a Comment