java help!! count number of upper and lower case letters
could someone help me with this.. thanks in advance!!!
Write a program that allows you to input a string. Your program will count and extract and display the number of upper case letters and lower case letters.
Sample output:
Enter a string: Hello World
Upper case letters: 2 - HW
Lower case letters: 8 – elloorld
finally im done with it.......
here is what i did ....... hope this reference can help to newbies like me..
Code:
import java.io.*;
public class casestudy4 {
public static void main(String[] args)throws IOException {
BufferedReader enterstring=new BufferedReader(new InputStreamReader(System.in));
String inputstring;
String upper ="";
String lower ="";
String other ="";
System.out.print("Enter a String: ");
inputstring=enterstring.readLine();
for (int i = 0; i < inputstring.length(); i++) {
char thisChar = inputstring.charAt(i);
if (thisChar >= 65 && thisChar <= 90) {
upper += thisChar;
} else if (thisChar >= 97 && thisChar <= 122) {
lower += thisChar;
} else {
other += thisChar;
}
}
System.out.println("Upper case letters: " + upper.length() + " - " + upper);
System.out.println("Lower case letters: " + lower.length() + " - " + lower);
System.out.println("Other: "+other);
}
}
thread close......