I wrote the method 'charCount()' to return String 'chc', but the netbean is forcing me to return null. Does the 'return null' also debarring me use the 'chc' outside this method,or it is well returned. Being new to java I am confused.
// static String chc ;
public static String charCount(String [] a){
String chc ;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length(); j++) {
char ch = a[i].charAt(j);
int charcout = a[i].length();
chc= Character.toString(ch)+""+Integer.toString(charcout)+" ";
// String chc= ch + "" + charcout + " ";
return chc;
//System.out.print(chc);
}
}
return null; //NETBEAN IS FORCING ME TO WRITE THIS TO AVOID COMPILE TIME ERROR
}
I need help to rectify this code to avoid return null.
return nullat the end of the method probably will become irrelevant. (Callingreturnin the middle of the loop means both loops will never execute more than once.)