a) dein code ist nen bissl komisch geschweift-geklammert.
b) da ich Hilfe.zufall() nicht habe, gibts eben zufall() als eigene funktion.
c) int[10] statt 100 nur der übersichtlichkeit halber.
richtig:
Code:
import java.util.Arrays;
public class Zahlenproblem {
private static int zufall(int min, int max) {
return min + (int) ((max+1-min) * Math.random());
}
/**
* @param args
*/
public static void main(String[] args) {
int max = -1;
int min = 101;
int[] Zahlenfeld = new int[10];
for (int i = 0; i < Zahlenfeld.length; i++) {
Zahlenfeld[i] = zufall (1,100); // (int) (100 * Math.random() + 1.0);
System.out.println("zahl " + i + " == " + Zahlenfeld[i]);
if (max < Zahlenfeld[i]) {
max = Zahlenfeld[i];
}
if (min > Zahlenfeld[i]) {
min = Zahlenfeld[i];
}
}
Arrays.sort(Zahlenfeld);
for (int s : Zahlenfeld) {
System.out.println(s);
}
System.out.println("Maximum:" + max);
System.out.println("Minimum;" + min);
}
}
edit:
ausserdem war
Code:
for(int s : Zahlenfeld)
System.out.println(i);
falsch. muss
for (int i: ...) oder
System.out.println(s); heissen. typischer copy-und-paste fehler.