Created
February 8, 2012 10:04
-
-
Save carlossaraiva/1767620 to your computer and use it in GitHub Desktop.
[ESD] Aula 01 - Homework 02.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*2 - Gerar um vetor com 100 números de 0 a 99. Pedir para o usuário digitar 3 números. | |
Verificar quantos pontos o usuário fez, sendo que toda vez que um dos números aparece ele conta um ponto.*/ | |
import java.util.*; | |
public class HomeWork02 { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
int[] vetorUsuario = new int[3]; | |
int[] vetor = new int[100]; | |
int totalPontos = 0, totalPontosAux; | |
Scanner entrada = new Scanner(System.in); | |
//Faz a chamada da função e armazena um vetor com números aleatórios. | |
vetor = criarVetorRand(vetor); | |
debugVetor(vetor); | |
//Começa a entrada de dados do usuário. | |
for(int i = 0; i < vetorUsuario.length; i++) | |
{ | |
System.out.println("DIgite o " + i +"º" + " número: "); | |
vetorUsuario[i] = entrada.nextInt(); | |
} | |
//Faz a comparação e a totalização de pontos | |
for(int i = 0; i < vetorUsuario.length; i++) | |
{ | |
totalPontosAux = somarPontos(vetorUsuario[i],vetor); | |
totalPontos = totalPontos + totalPontosAux; | |
} | |
//Somente uma condicional para mensagens super especiais. *>* (I'm a fucking retard, i know..mmkay) | |
if(totalPontos == 0) | |
{ | |
System.out.println("Não fez nenhum ponto.. Fuck off, loser!"); | |
} | |
else | |
{ | |
System.out.println("Você fez o total de: " + totalPontos +" ponto(s)!!!" ); | |
System.out.println("Nosso sistema de alienação ariticial também identificou que logo ocorrerá uma tragédia em sua vida. Tenha um bom dia!"); | |
} | |
} | |
//Início das funções.. uma cria um vetor com números aleatórios e outro faz a comparaçãoe totalização de pontos | |
public static int[] criarVetorRand(int[] vetor) | |
{ | |
Random rand = new Random(); | |
for(int i = 0; i < 100; i++) | |
{ | |
vetor[i] = rand.nextInt(100); | |
} | |
return vetor; | |
} | |
public static int somarPontos(int numeroUsuario, int[] vetor ) | |
{ | |
int ponto = 0; | |
for (int i = 0; i < vetor.length; i++) | |
{ | |
if (numeroUsuario == vetor[i]) | |
{ | |
System.out.println("Você acertou o número: " + numeroUsuario + " \tna posição: " + i + "." + " \t+1 mothafucka!"); | |
ponto++; | |
} | |
} | |
return ponto; | |
} | |
//Apenas para o propósito de visualizar o vetor criado. | |
public static void debugVetor(int array[]) | |
{ | |
System.out.print("\narray: "); | |
for (int i = 0; i < array.length; i++) | |
{ | |
System.out.println("[" + i + "]" + array[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment