Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Zufallszahlen in Java

Empfohlene Antworten

Veröffentlicht

Hallo

Ich habe folgendes Problem:

Ich will zwei verschiedene Array mit verschiedenen Zufallszahlen von 1 - 104 belegen.

Beide Arrays werden in verschiedenen Methoden verwendet. Es werden jedoch beiden Arrays immer die selben Werte zugewießen. Wo liegt der Fehler bzw, wie kann ich sonst noch Zufallszahlen erzeugen?

In c++ gehts ja noch über die Zeit. Geht das in Java auch?

Hier mein code:


class sechsNimmt{

static int arrayplayer[], arrayPC[], arrayKarten[];


        public static void main(String[] args)

        {

                Out.println("Sechs Nimmt");

                Out.println("-----------");

                getArrayPlayer();

        }


        static void getArrayPlayer()

        {

                int n;

                arrayplayer = new int[10];

                for (n = 0; n <=9 ; n++)

                {arrayplayer[n] = (int)(Math.random() *103);

                }

                Out.print(" Karten des Spielers: ");

                int j = 0;

                while (j <= 9 )

                {       Out.print(" " + (arrayplayer[j]) + " ");

                        j++;

                }

                Out.println(" ");

                getArrayPC();

}

        static void getArrayPC()

        {

                arrayPC =new int [10];

                int i;

                for (i = 0; i <= 9; i++)

                {arrayPC[i] = (int)((Math.random() * 104)/(Math.random()*25) *10) ;

                }

                Out.print(" Karten des Computers: ");

                int k = 0;

                while (k <= 9)

                {

                        Out.print(" " + arrayplayer[k] + " ");

                        k++;

                }

                Out.println(" ");

        }

}


Hat sich bereits erledigt...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.