|
|
|
stored in 4 arrays as follows:
studID[0] = 314 name[0] = "John Doe" major[0] = "Math" level[0] = 3 studID[1] = 123 name[1] = "Mary Jane" major[1] = "Psych" level[1] = 1 studID[2] = 876 name[2] = "Peter Pan" major[2] = "Chem" level[2] = 2 |
Multiple arrays where the elements are "synchronized" to represent information of the same item are called:
|
Values located at the same index in each array are implicitly the fields of the same record.
Wikipedia page: click here
public class ParallelArray1 { public static void main(String[] args) { int[] studID = {314, 123, 876}; String[] name = {"John Doe", "Mary Jane", "Peter Pan"}; String[] major = {"Math", "Psych", "Chem"}; int[] level = {3, 1, 2}; /* ---------------------------------------------- Print the information in the parallel arrays ---------------------------------------------- */ for ( int i = 0; i < studID.length; i++ ) { System.out.print( studID[i] + "\t"); // \t = tab character System.out.print( name[i] + "\t"); System.out.print( major[i] + "\t"); System.out.print( level[i] ); System.out.println(); } } } |
How to run the program:
|