r/javahelp • • Dec 12 '19

Adding values to 2D array

Hi all, I have a 2D array with 20 preset values, but as part of the project we need to add up to 100 values Here is my code as follows

Public static void PrintDiggerDetails() { String [][] DiggerList = new String[99][7]; System.out.println("==Digger Data Table=="); (Next part covers headings for printing array) System.out.print(DiggerList[0][0]"Manufacturer"); System.out.print(DiggerList[0][1]"\t\tYear"); System.out.print(DiggerList[0][2]"\tPrice"); System.out.print(DiggerList[0][3]"\tArmLength"); System.out.print(DiggerList[0][4]"\tTrack Type"); System.out.print(DiggerList[0][5]"\tStatus"); System.out.print(DiggerList[0][6]"\tWeight); } (Below this all the preset values are stored down to [19][6]) I then have a method: static void AddNewDigger() { Scanner disc = new Scanner(system.in) String strPrDOpt; strPrDOpt = disc.nextLine(); System.out.println("Manufacturer: ");

System.out.println("Year: ");

System.out.println("Price: ");

System.out.println("Arm length : ");

System.out.println("Track type: ");

System.out.println("Status: ");

System.out.println("Weight: ");

How do i add to the 2D array using these values please

}

0 Upvotes

8 comments sorted by

View all comments

3

u/Wolfhammer69 Nooblet Brewer Dec 12 '19 edited Dec 12 '19

Format your code please.

If each Digger is going to contain year, price etc you would be better off creating a digger class with all those attributes so you can create diggers as needed to drop them into a Digger array for later retrieval.

2

u/ivandagiant Dec 12 '19

How is it a 3D array?

2

u/Wolfhammer69 Nooblet Brewer Dec 12 '19

Ooops my bad.... edited