I am stuck with a particular problem. Any help would be highly appreciable .
Suppose i am given rows=8 and column=5. How do i take a input from the user in the following manner.
Aacvg
Qwn&k
LOpyc
GYhcj
%&fgT
JUIOP
icgfd
Hu*hc
and then calculate the number of 'c' in the whole user defined pattern, which will give an output=5 here.
I tried to input each line as String and then convert it into a 2D char array but it wasn't working that way. Also how to limit the number of char per line to the number of column(here 5).
NB:- the input will be a whole line together and then the next line as a whole .... till row=8(for this example).
I would be very thankful if someone could tell me a way to do that.(I even considered array of arrays.)
I wrote the following code but it isn't working so if anyone can write the correct way to do it.
Scanner sc = new Scanner (System.in);
for(int i=0;i<row;i++){
String str;
str = sc.nextLine();
for(int j=0;j<column;j++){
char[] charArray = str.toCharArray();
a[i][j]= charArray[j];
if(a[i][j]=='c'){
count= count+1;
}
}
}