I'm working on a java program that has the following input:
A V V V VV V V V
E F V E VF E V E
C D V C VD B V C
A A V A VA G V A
V D V V VD E V V
A V V A VV V V A
and the following output:
R
R
R
R
R
R
So an R has to be printed if a column contains minimal one letter A-G, but a space has to be printed if there are only V's in the column. The code I have is:
Scanner inputc2 = new Scanner (new File("internalc"));
int sss = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
try{
matrix2[i][j] = inputc2.useDelimiter(" ").next().replaceAll(",", " ");
System.out.println(matrix2[i][j]);
temp2[sss] = matrix2[i][j];//change this
if(temp2[sss].indexOf("N") >= 0){
pc2.println(temp2[sss].replaceAll("N","R"));
}
if(temp2[sss].indexOf(' ') >= 0){
pc2.println(temp2[sss]);
}
sss++;
}
catch (java.util.NoSuchElementException e) {
// e.printStackTrace();
}
}
}
In the current program the temp2[sss] is exactly the same as matrix2[i][j], but it must be strings of columns. I hope that you can help me.
Kind regards, Bjorn
replace()instead ofreplaceAll(). Their names are really ambiguous, they should usereplaceAll()forreplace()andreplaceRegex()forreplaceAll().