public class SopaFileHunder {
protected char sopa[][];
private int punt=0;
private int maximo;
public SopaFileHunder(int largo,int ancho){
this.maximo=largo;
sopa=new char[largo][ancho];
}
public void Cargar
(String cargar
) { Object[] lines
= car.
lines().
toArray();
if(lines.length>0) {
sopa
= new char[lines.
length][((String)lines
[0]).
length()];
for (int i = 0; i < lines.length; i++) {
sopa
[i
]=((String)lines
[i
]).
toCharArray(); }
}
// TODO Auto-generated catch block
e.printStackTrace();
// TODO Auto-generated catch block
e.printStackTrace();
}
/* if(punt!=maximo) {
sopa[punt]=cargar.toCharArray();
punt++;
}
*/
}
public char getChar(int fila, int col) {
return sopa[fila][col];
}
public String getRow
(int posicion
) { for (int i = 0; i < sopa[posicion].length; i++) {
sor=sor+sopa[posicion][i];
}
return sor;
}
public String getCol
(int posicion
) { for (int i = 0; i < sopa[posicion].length; i++) {
sor=sor+sopa[posicion][i];
}
return sor;
}
public String getDiagonal
(int xoy,
int yex,
boolean dire
) { if(dire==true) {
int i= xoy; int j=yex;
while((i<sopa.length)&&(j<sopa[i].length)) {
sor+=sopa[i][j];
i++;
j++;
}
}else {
int i= xoy; int j=yex;
while((i<sopa.length)&&(j<=0)){
sor+=sopa[i][j];
i++;
j--;
}
}
return sor;
}
public void printSopa() {
for (int i = 0; i < sopa.length; i++) {
System.
out.
println(sopa
[i
].
toString()); }
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.Callable;
public class WordSopaThread implements Callable<Integer> {
super();
this.word=word;
this.f=f;
}
@Override
// TODO Auto-generated method stub
return line.indexOf(word);
// TODO Auto-generated catch block
return -1;
// TODO Auto-generated catch block
return -1;
}
}
}
public class SopaMain {
static String[] words
= {"cazuela",
"sarten",
"martes",
"lunes",
"pepe"};
public static void main
(String[] args
) { // TODO Auto-generated method stub
List<Future> list=new ArrayList<>();
ExecutorService executor=Executors.newFixedThreadPool(4);
for(int i=0;i<10;i++) {
list.
add(executor.
submit(new WordSopaThread
(words
[i
],
new File("sopa.data")))); }
for(Future f:list) {
try {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public int x;
public int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
public class SopaApp {
// TODO Auto-generated method stub
SopaFileHunder zw=new SopaFileHunder(200,200);
WordSopaThread wd=new WordSopaThread(null, null);
zw.printSopa();
System.
out.
println(zw.
getChar(0,
2)); System.
out.
println(zw.
getRow(0)); System.
out.
println(zw.
getCol(1)); System.
out.
println(zw.
getDiagonal(1,
0,
true));
}
}