This is java, and I need some arrary help. I am looking to convert this normal a
ID: 3807578 • Letter: T
Question
This is java, and I need some arrary help.
I am looking to convert this normal array I have into a 2d array.
Any ideas?
public class Moives {
public static void main(String[] args) {
DVD[] movies=new DVD[7];
movies[0]= new DVD ("The Godfather", "Francis Ford Coppola", 1972, 24.95, true);
movies[1]= new DVD ("District 9", "Neill Blokamp", 2009, 19.95, false);
movies[2]= new DVD ("Iron Man", "Jon Favreau", 2008, 15.95, false);
movies[3]= new DVD ("All About Eve", "Joseph Mankiewicz", 1950, 17.50, false);
movies[4]= new DVD ("The Matrix", "Andy & Lana Wachowski", 1999, 19.95, true);
movies[5]= new DVD ("Iron Man 2", "Jon Favreau", 2010, 22.99, false);
movies[6]= new DVD ("Casablanca", "Michael Curtiz", 1942, 19.95, false);
Sorting.selectionSort(movies);
for(DVD dvd:movies)
System.out.println(dvd);
}
}
Explanation / Answer
HI, I have converted normal array into 2-D array.
Please let me know in case of any issue.
public class Moives {
public static void main(String[] args) {
DVD[][] movies=new DVD[4][7]; // row = 4, column = 7
for(int i=0; i<movies.length; i++){ // row interation
movies[i][0]= new DVD ("The Godfather", "Francis Ford Coppola", 1972, 24.95, true);
movies[i][1]= new DVD ("District 9", "Neill Blokamp", 2009, 19.95, false);
movies[i][2]= new DVD ("Iron Man", "Jon Favreau", 2008, 15.95, false);
movies[i][3]= new DVD ("All About Eve", "Joseph Mankiewicz", 1950, 17.50, false);
movies[i][4]= new DVD ("The Matrix", "Andy & Lana Wachowski", 1999, 19.95, true);
movies[i][5]= new DVD ("Iron Man 2", "Jon Favreau", 2010, 22.99, false);
movies[i][6]= new DVD ("Casablanca", "Michael Curtiz", 1942, 19.95, false);
}
for(int i=0; i<movies.length; i++){ // sorting each row
Sorting.selectionSort(movies[i]);
}
for(DVD dvds[] : movies)
for(dvd : dvds)
System.out.println(dvd);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.