-2

I am trying to print out names with their associated information. I want their age, salary, insurance, etc. I am trying to use a for loop to accomplish this, but I'm obviously missing something. I also don't want it to total the ages, I want it individually. I just can't find a way to print all of my information.

public static double printArray(int[] noclue, String[] name, double[] age, double[] salary, double[] insurance, double[] expense, double[] savings) 
{
    int total = 0;
    String names = "";     
    for (int i = 0; i < noclue.length; i++)
    {    
         total = total + noclue[i] 
         names = name[i];         
    }
return total;
return names;
}   
}

In the main:

System.out.println(array.printArray(noclue, name, age, salary,insurance, expenses, savings));
Michael K.
  • 43
  • 1
  • 9
  • Function can return only once, so your second return statement will be ignored. A good IDE should tell you that – vincrichaud Apr 09 '18 at 14:36
  • 3
    While this is not what your asking for: Your main problem is that you use a horrible data structure. Instead of having half a dozen different arrays you should have created your own custom class that groups together the infromation that belongs together and have a single array/list of that custom class. – OH GOD SPIDERS Apr 09 '18 at 14:36
  • @OHGODSPIDERS Buddy, let's not criticize him too severely. He is just a beginner anyways and may not know how to use classes yet. :) – Raymo111 Apr 09 '18 at 14:37
  • Your function printArray just add noclue to the variable total. And then return this total. There's no way it could print something since you print nothing in the function. Then you print the result of the function that is a Double, it's logical that it will print only a number – vincrichaud Apr 09 '18 at 14:38
  • 2
    @Raymo111 I don't see flaming, just constructive criticism. – Federico klez Culloca Apr 09 '18 at 14:38
  • @FedericoklezCulloca Hmm. I might be using that word wrong then. – Raymo111 Apr 09 '18 at 14:39
  • I need to stop asking questions.. Because as soon as I do, I figure out what I'm supposed to do. I do appreciate the feedback though, and don't care if it sounds mean. Sometimes the most mean sounding people care more than you think. – Michael K. Apr 10 '18 at 15:50

1 Answers1

-1

How about this:

public static void printArray(int[] noclue, String[] name, double[] age, double[] salary, double[] insurance,
        double[] expense, double[] savings) {
    for (int i = 0; i < noclue.length; i++) {
        System.out.println(noclue[i] + " " + name[i] + " " + age[i] + " " + salary[i] + " " + insurance[i]);
    }
}
Raymo111
  • 514
  • 8
  • 24