invoke a method named printArray that prints my random numbers array

Hunter Isaacs :

So far i have made a random numbers array but i am stuck on how to make a printarray method that i can call within the main. I need to invoke print array in the same class and print out all elements separated by one space

public class HunterIsaacsHw6
{
public static void main(String[] args)
{
System.out.println("Java, Online, Hunter Isaacs, hw6"); 
 // define the range 
int max = 100; 
int min = 1; 
int range = max - min + 1; 
// combining both statements in one
double doubleArray[] = new double[10]; 
// generate random numbers within 1 to 10 
for (int i = 0; i < 10; i++) {  
    doubleArray[i]  = (Math.random() * range) + min; 
} 
}
public static double printArray(doubleArray[]){
    for(double n: doubleArray){
        System.out.println(n+" ");
    }
}
Scary Wombat :

Your method declaration is incorrect and you are not even calling it. Try:

public static void main(String [] args)
{

    System.out.println("Java, Online, Hunter Isaacs, hw6"); 
     // define the range 
    int max = 100; 
    int min = 1; 
    int range = max - min + 1; 
    // combining both statements in one
    double doubleArray[] = new double[10]; 
    // generate random numbers within 1 to 10 
    for (int i = 0; i < 10; i++) {  
        doubleArray[i]  = (Math.random() * range) + min; 
    } 

    printArray(doubleArray);
}
public static void printArray(double doubleArray[]){
        for(double n: doubleArray){
            System.out.println(n);
        }
}

Also, nothing is being returned from printArray so it should be declared as void

Also I prefer the declaration as double[] doubleArray

edit

Also System.out.println(n); is sufficient, there is no need to append a space

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=296422&siteId=1