Comparar palavras iguais
Bom dia, tenho o seguinte codigo. que teoricamente, compararia falavras iguais em uma frase... so que esta com um erro, alguem pode me ajudar?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author SECRETARIA1
*/
public class Ex8 {
public static void main(String[] args) {
ArrayList<String> data = new ArrayList<String>();
Scanner teclado = new Scanner(System.in);
String entrada, caracter, saida = "", temp = "";
int a = 0, controlegeral=0, b=0, t=0, j=0, p=0;
String[] vets = new String[100];
String[] vetr = new String[100];
vets[0]="";
char l = 0;
System.out.println("Digite a frase 1: ");
entrada = teclado.nextLine();
while(controlegeral<=(entrada.length()-1)){
l = entrada.charAt(a); //pega um caracter
caracter = ""+l;//convete para String
vets[b] += caracter;
if(caracter.equals(" ")){
b++;
a++;
controlegeral++;
vets[b]="";
}else{
a++;//prepara para pegar o proximo caracter
controlegeral++;
}
}
//System.out.println(b);
for(int i =0; i<=b;i++)
{
t=i;
t++;
while(vets[t]!= null)
{
if(vets[i].equals(vets[t]))
{
vetr[j]=vets[i];
j++;
System.out.println("loop?");
}
if(p!=0){
t++;
}
p++;
}
}
System.out.println(j);
t=0;
while(vetr[t]!=null){
System.out.println(vetr[t]);
t++;
}
}
}Discussão (1)
Carregando comentários...