/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
import java.util.Scanner ;
class Ler {
static Scanner in
= new Scanner
( System .
in ) ; public static int umInt( ) {
return in.nextInt ( ) ;
}
}
class Totoloto {
public static boolean existe( int [ ] arr, int num) {
for ( int i= 0 ; i < arr.length ; ++ i) {
if ( arr[ i] == num) {
return true ;
}
}
return false ;
}
public static void main
( String [ ] args
) { int aux, i;
int [ ] x = new int [ 6 ] ;
System .
out .
println ( "Introduza inteiros entre 1 e 49 não repetidos:" ) ;
for ( aux = 0 ; aux < 6 ; aux++ ) {
i = Ler.umInt ( ) ;
while ( i <= 0 || i >= 50 || existe( x, i) ) // so entra se i tiver entre 1 e 49
{
System .
out .
println ( "Introduza um inteiro valido e não repetido:" ) ; i = Ler.umInt ( ) ;
}
x[ aux] = i;
}
for ( aux = 0 ; aux < 6 ; aux++ ) {
System .
out .
println ( aux
+ 1 + " elemento da chave= " + x
[ aux
] ) ; }
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgppbXBvcnQgamF2YS51dGlsLlNjYW5uZXI7CgpjbGFzcyBMZXIgewoKCXN0YXRpYyBTY2FubmVyIGluID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKCXB1YmxpYyBzdGF0aWMgaW50IHVtSW50KCl7CgkJcmV0dXJuIGluLm5leHRJbnQoKTsKCX0KfQoKY2xhc3MgVG90b2xvdG8gewoJCglwdWJsaWMgc3RhdGljIGJvb2xlYW4gZXhpc3RlKGludFtdIGFyciwgaW50IG51bSl7CgkJZm9yIChpbnQgaT0wOyBpIDwgYXJyLmxlbmd0aDsgKytpKXsKCQkJaWYgKGFycltpXSA9PSBudW0pewoJCQkJcmV0dXJuIHRydWU7CgkJCX0KCQl9CgkJCgkJcm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