Created
August 3, 2017 17:03
-
-
Save lucasapoena/dc23a2bdaddef19dabc4c8c41a374f5c to your computer and use it in GitHub Desktop.
Classe referente ao Módulo02 - Exercício02 - Triadworks CrossCode
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
import java.util.Collection; | |
import java.util.HashSet; | |
import java.util.Random; | |
/* | |
* Exercicio 02 - Triadworks - CrossCode | |
* | |
* Autor: Lucas Apoena - [email protected] | |
* | |
* Descrição: | |
* Crie um programa que gere 6 números aleatórios entre 1 e 60 para um sorteio da Mega-Sena. | |
* Os números não podem se repetir assim como no jogo. | |
* | |
*/ | |
public class Modulo02Exercicio02 { | |
public static void main(String[] args) { | |
int inicioIntervalo = 1; | |
int finalIntervalo = 60; | |
int qtdNumerosSorteados = 6; | |
Collection<Integer> numerosMegaSena = new HashSet<Integer>(); | |
while(numerosMegaSena.size() < qtdNumerosSorteados) { | |
numerosMegaSena.add(sortearNumero(inicioIntervalo, finalIntervalo)); | |
} | |
System.out.println("Os numéros sorteados foram: "+numerosMegaSena); | |
} | |
private static int sortearNumero(int inicioIntervalo, int finalIntervalo) { | |
Random random = new Random(); | |
int numeroSorteado = random.nextInt(finalIntervalo - inicioIntervalo + 1) + inicioIntervalo; | |
return numeroSorteado; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment