ctcodre
24-02-2008, 17:23
Ciao ragazzi. Ho questo codice:
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
Random aGene = new Random();
Random intGene = new Random();
Random charUGene = new Random();
Random charLGene = new Random();
Generator myGene = new Generator();
int choice = input.nextInt();
for(int i = 0; i < choice; i++) {
int a = aGene.nextInt(3);
switch( a ) {
case 0: {
int x = intGene.nextInt(10);
System.out.printf("%d", myGene.getGeneratedInt(x));
break;
}
case 1: {
int x = charLGene.nextInt(26);
System.out.printf("%c", myGene.getGeneratedLChar(x));
break;
}
case 2: {
int x = charUGene.nextInt(26);
System.out.printf("%c", myGene.getGeneratedUChar(x));
break;
}
default: {
System.out.println("This program is perfect! :P");
break;
}
}
}
}
}
Il problema è che tutti i numeri generati dalla parte evidenziata valgono sempre 0. Mai un valore diverso, solo 0. Non so dov'è il problema. Grazie in anticipo. :)
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
Random aGene = new Random();
Random intGene = new Random();
Random charUGene = new Random();
Random charLGene = new Random();
Generator myGene = new Generator();
int choice = input.nextInt();
for(int i = 0; i < choice; i++) {
int a = aGene.nextInt(3);
switch( a ) {
case 0: {
int x = intGene.nextInt(10);
System.out.printf("%d", myGene.getGeneratedInt(x));
break;
}
case 1: {
int x = charLGene.nextInt(26);
System.out.printf("%c", myGene.getGeneratedLChar(x));
break;
}
case 2: {
int x = charUGene.nextInt(26);
System.out.printf("%c", myGene.getGeneratedUChar(x));
break;
}
default: {
System.out.println("This program is perfect! :P");
break;
}
}
}
}
}
Il problema è che tutti i numeri generati dalla parte evidenziata valgono sempre 0. Mai un valore diverso, solo 0. Non so dov'è il problema. Grazie in anticipo. :)