Java programmieren Hilfe!?
Ich schreibe morgen eine Klassenarbeit also wenn möglich bittte so früh wie möglich antworten.
ich soll eine zufallszahl von 0 bis 1 milliarde erstellen und dann noch 20 weitere zufallszahlen aber die müssen immer kleiner als die vorherige sein.
ich bin noch nicht fortgeschritten es ist die erste klassenarbeit also macht es bitte nicht kompliziert mit sachen importen oder so bloß mit sachen wie for schleifen referenzen usw.
Danke für die Antworten!
1 Antwort
also wenn man KI fragt
import java.util.Random;
public class Zufallszahlen {
public static void main(String[] args) {
// Erstelle ein Random-Objekt
Random random = new Random();
// Erstelle eine Zufallszahl von 0 bis 1 Milliarde
int zufallszahl = random.nextInt(1000000000);
// Gib die erste Zufallszahl aus
System.out.println("Die erste Zufallszahl ist: " + zufallszahl);
// Erstelle eine Schleife, um 20 weitere Zufallszahlen zu erzeugen
for (int i = 0; i < 20; i++) {
// Erstelle eine neue Zufallszahl, die kleiner als die vorherige ist
zufallszahl = random.nextInt(zufallszahl);
// Gib die neue Zufallszahl aus
System.out.println("Die nächste Zufallszahl ist: " + zufallszahl);
}
}
}