I want to make a random color code generator and it also works, but instead of simply giving me the color it also spits out "null" right before it.
So in the end my output looks like [nullBlue, nullgreen, nullyellow, nullred] anybody know a quick fix?
public class rndmcode {
int[] secretcode = new int[4];
String[] farbcode = new String[4];
public rndmcode() { // array "secretcode" wird definiert
for (int i = 0; i < 4; i++) { //Schleife um eine Randomziffer von 1-6 zu erstellen und
Random zufallszahl = new Random();
int rndnumber = zufallszahl.nextInt(7); //Die Zahlen 1-6 sind meine Farben, die vorrerst nur Zahlen sind
switch (rndnumber) {
case 1:
farbcode[i] += "Blau";
break;
case 2:
farbcode[i] += "Rot";
break;
case 3:
farbcode[i] += "Gelb";
break;
case 4:
farbcode[i] += "Grün";
break;
case 5:
farbcode[i] += "Lila";
break;
case 6:
farbcode[i] += "Orange";
default:
if (farbcode == null)
break;
}
}
}
public String stringo() {
String s = "[";
for (String element : farbcode) {
s += element;
s += ", ";
}
s += "]";
return s;
}
}