This discussion is archived
1 Reply Latest reply: Apr 3, 2007 1:11 PM by 807606 RSS

Learning arrays

807606 Newbie
Currently Being Moderated
I am in the process of teaching myself arrays via online documents...however, so far it is not going so well. I am trying to create a sample program which stores the last and first names of an unknown amount of students (max=100) as well as storing three grades for each student and the average of the three grades.
I set up the basis for the array based on an online tutorial and this is how it looks:
import java.util.*;
public class Baillie {
     public static void main(String[] args)
          System.out.println("You will be entering student names and grades.\nPlease enter the requested information one item per line.\nHit return after each line you type.\nWhen you have run out of students to enter, give the single\ncharacter quote&.&quote as the Last name.");
          Scanner keyboard = new Scanner(;
          String[] LastNames = new String[99];
          String[] FirstNames= new String[99];
          Double[] Grade1= new Double[99];
          Double[] Grade2= new Double[99];
          Double[] Grade3= new Double[99];
          Double[] Averages= new Double[99];

is that how I want to set it up or am i doing it completely wrong?
...Then my code gets ugly...I am having all kinds of trouble storing user information in the array. It wont convert to the right types it wont store the right information. NOTE: BEAR WITH ME...I AM TRYING TO TEACH MYSELF! if you don't wanna help...i dont mind....but i dont need sarcastic posts.
Anyway here is what is not working (i know its ugly):
for (i=0; i < 100; i++)
               System.out.println("Last Name?");
               LastNames[i-1] = keyboard.nextString();
               if (LastNames[i-1].equals("."))
               System.out.println("Fist Name?");
               FirstNames[i-1] = keyboard.nextDouble();
               Grade1[i-1] = keyboard.nextDouble();
               Grade2[i-1] = keyboard.nextDouble();
               Grade3[i-1] = keyboard.nextDouble();

Finally, i have no idea how to print out the array...any help with that would be greatly appreciated.