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.

Empfohlene Antworten

Veröffentlicht

Abend.

Hoffe jemand kann mir helfen.

Sollten ein Programm mit Zufallszahlen erzeugen.

Allerdings sollen die ausgegebenen Zahlen

als ganze zahlen zwischen 1- 100

ausgegeben werden.

Wie kann man dies verändern.

habe nun folgendes Programm geschrieben, komme aber nicht weiter.:confused:

Danke für eure Hilfe im Vorraus.

import javax.swing.*;

//import java.util.* ;

public class ctrl

{

String a = JOptionPane.showInputDialog("Anzahl der Zufallszahlen eingeben:");

int n=Integer.parseInt (a); // Anzahl der Zufallszahlen

double R[]=new double [n]; // erzeugt Platz fuer n Zahlen

// int i;

public ctrl()

{

erzeugenderZahlen();

mittelwertBerechnen();

maximumBerechnen();

haeufigkeitBestimmen();

}

public void erzeugenderZahlen ()

{

// Zufallszahlen:

for (int i=0; i<n; i++)

{

R= 100 * Math.random(); // erzeuge Zufallszahlen

System.out.println( R);

System.out.println();

}

}

public void maximumBerechnen()

{

//for ( int i=0; i<n; i++) R=Math.random();

double max=R[0];

for (int i=1; i<n; i++)

if (R>max) max=R;

System.out.println("Das Maximum ist :"+max );

System.out.println( );

Also du kannst dein Ergebniss Array in int ändern


int R[]=new int [n]; // erzeugt Platz fuer n Zahlen

Und dann änderst du die Berechnung in

R[i]= (int)(Math.random()*100+1)

Alternativ kannst du auch die Klasse Random aus dem java.util package nutzen

Random zufall = new Random(new Date().getTime());

R[i] = zufall.nextInt(100)+1;

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.