//Pesquisando string e mostrando linha e coluna - localização
import java.util.Scanner;
public class PROJETO {
private static int Pesq ( ) {
J jht = new J ( );
jht.textbackground ( jht.WHITE );
jht.Moldura ( ( short ) 1, ( short ) 24, ( short ) 2, ( short ) 78 );
jht.title ( " " );
int i, j, x = 0, y = 0, k = 0, cop = 0;
char [ ] oc = new char [ 50 ];
String [ ] [ ] busca = {{ "uma" }};
boolean achou = false;
int acheiI = -1, acheiJ = -1;
String [ ] [ ] texto = {
{"No", "Meio", "do", "Caminho\n"},
{"Carlos", "Drummond", "de
Andrade\n"},
{"No", "meio", "do", "caminho", "tinha", "uma", "pedra\n"},
{"Tinha", "uma", "pedra", "no", "meio", "do", "caminho\n"},
{"Tinha", "uma", "pedra\n"},
{"No", "meio", "do", "caminho", "tinha", "uma", "pedra\n"},
{"Nunca", "me", "esquecerei", "desse", "acontecimento \n"},
{"Na", "vida", "de", "minhas", "retinas", "tão", "fatigadas. \n"},
{"Nunca", "me", "esquecerei", "que", "no", "meio", "do", "caminho\n"},
{"Tinha", "uma", "pedra\n"},
{"Tinha", "uma", "pedra", "no", "meio", "do", "caminho\n"},
{"No", "meio", "do", "caminho", "tinha", "uma", "pedra\n"}};
jht.textcolor ( jht.LIGHTRED );
jht.gotoxy ( ( short ) 19, ( short ) 2 );
System.out.printf ( "MARCANDO
OCORRÊNCIAS DE CARACTERES EM ARRAY " );
jht.textcolor ( jht.BLACK );
jht.gotoxy ( ( short ) 29, ( short ) 4 );
System.out.printf ( "Imprimindo
abaixo o array " );
for ( i = 0; i < texto.length; i++ ) {
jht.gotoxy ( ( short ) 24, ( short ) i + 6 );
for ( j = 0; j < texto [ i ].length; j++ ) {
System.out.printf ( "%s", texto [ i ] [ j ] + " ");
}
}
for ( i = 0; i < texto.length; i++ ) {
for ( j = 0; j < texto [ i ].length; j++ ) {
k = 0;
y = 0;
if ( texto [ i ] [ j ].contains ( busca [ k ] [ y ] ) ) {
jht.textcolor ( jht.LIGHTBLUE );
System.out.printf ( "\nA string
" );
jht.textcolor ( jht.LIGHTRED );
System.out.printf ( "%s", busca [ k ] [ y ] );
jht.textcolor ( jht.LIGHTBLUE );
System.out.printf ( " foi
encontrada na linha " );
jht.textcolor ( jht.LIGHTRED );
System.out.printf ( "%d", i );
jht.textcolor ( jht.LIGHTBLUE );
System.out.printf ( " e coluna
" );
jht.textcolor ( jht.LIGHTRED );
System.out.printf ( "%d ", j );
jht.getche ( );
}
}
}
// ////////////////////////////////////////////////////////////
jht.getche ( );
System.exit ( 0 );
return 0;
}
public static void main ( String [ ] args ) {
Pesq ( );
}
}
Nenhum comentário:
Postar um comentário
Observação: somente um membro deste blog pode postar um comentário.