This question already has an answer here:
how to print the maximum value using method from a method of java random numbers . the output of the maximum value i got is [I@3d4eac69 and i don't know if my code for the maximum method is right.
public static void getRandom(int [] newArray){
Random rand = new Random();
for(int x=0;x < newArray.length;x++){
newArray[x] = rand.nextInt(1000) ;
}
}
public static void getMaxValue(int[] array) {
int maxValue = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > maxValue) {
maxValue = array[i];
}
}}
public static void main(String[] args) {
Scanner m = new Scanner(System.in);
System.out.print("Enter the number of random integer: ");
int number = m.nextInt();
int [] num = new int[number];
getRandom(num);
System.out.print("The random integer :");
for(int i=0;i<num.length;i++){
System.out.print(num[i] + " "); }
System.out.println();
getMaxValue(num);
System.out.println("The maximum: " + num);
}
}
Aucun commentaire:
Enregistrer un commentaire