Quantcast
Channel: Programação - GUJ
Viewing all articles
Browse latest Browse all 33093

Valores repetidos no vetor

$
0
0

@thunanchiu escreveu:

Como faço para comparar no vetor os numeros repetido e dizer quais os numeros repetidos e a quantidade que foram repetidos. Fiz de uma maneira, mas toda vez que digito um número, ele diz que aquele numero foi repetido tantas vezes. Eu quero que no final ele só diga os números repetidos e quantas vezes foram repetidos.

public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	
	int quant;
	int cont =0;
	int atual;
	
	System.out.println("Digite o tamanho do vetor");
	quant = s.nextInt();
	
	int vetValor[] = new int [quant];
	int valor;
	int vetDif[] = new int [quant];
	int vetIgual[] = new int [quant];
	
	for(int i=0; i<vetValor.length;i++){
		System.out.println("Digite os valores");
		valor = s.nextInt();
		vetValor[i] = valor;
	}
	
	
	for(int i=0; i< vetValor.length;i++){
		atual = vetValor[i];
		cont =0;
		for(int j=0; j<vetValor.length;j++){
			
			if(vetValor[j] ==atual){
				cont++;
				vetIgual[i] = atual;
			}else{
				vetDif[j] = atual;
				
			}
			
		}

Mensagens: 2

Participantes: 2

Ler tópico completo


Viewing all articles
Browse latest Browse all 33093


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>