Friday, August 23, 2013

Please have a look the codes

Please have a look the codes

Write a program to read a string from the command-line arguments,count the
number of occurrence for each uppercase or lowercase letter contained in
it. (Hint: define two arrays of size 26 to save the number of uppercase
letter occurrence and lowercase letter occurrence in the string
respectively).
The above is my homework, I have done it so far as:
int[]loweroccurrence={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26};
int[]upperoccurrence={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26};
String a=args[0];
String lowercase="abcdefghijklmnopqrstuvwxyz";
String uppercase="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i=0,j=0,k=0;
for(j=0;j<26;j++){
for(i=0;i<a.length();i++){
if(a.charAt(i)==lowercase.charAt(j)){
System.out.print(loweroccurrence[i]);
}
Obviously, it is wrong, as the question asks to use two arrays to store
the occurrence number for both upper and lower letter, I have no idea how
to print out the result as a number by using arrays, please help, cheers
guys!

No comments:

Post a Comment