Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Create a method multiply(), that receives the 2D array you created in the program below as as an input, multiplies all of its elements and displays the product.

Hint: your method won’t return anything

import java.util.*;

public class Two_D_Ragged {

public static void Using_array_class(int R_array[][]) {

System.out.println("");

System.out.println("using Arrays class Through the Ragged Array");

//Array.toString method is used to show array elements in R_array[0]

System.out.println(Arrays.toString(R_array[0]));

//Array.toString method is used to show array elements in R_array[1]

System.out.println(Arrays.toString(R_array[1]));

//Array.toString method is used to show array elements in R_array[2]

System.out.println(Arrays.toString(R_array[2]));

} //end of Using_array_class method

public static void Using_for_each(int R_array[][]) {

System.out.println("for-each-loop Through the Ragged Array");

int k = 0;

//prints elements in R_array[0]

for (int i:R_array[0]) {

System.out.print(R_array[0][k] +" ");

k++;

}

System.out.println("");

int l = 0;

//prints elements in R_array[1]

for (int i:R_array[1]) {

System.out.print(R_array[1][l] +" ");

l++;

}

System.out.println("");

int m = 0;

//prints elements in R_array[2]

for (int i:R_array[2]) {

System.out.print(R_array[2][m] +" ");

m++;

}

} //end of Using_for_each method

public static void Using_for_loop(int R_array[][]) {

System.out.println("for-loop Through the Ragged Array");

for (int i = 0; i < R_array.length; i++) {

for (int j = 0; j < R_array[i].length; j++) {

System.out.print(R_array[i][j]+ " ");

}

System.out.println("");

}

}

public static void main(String[] args) {

int[][] R_array = new int [3][];

R_array[0] = new int[]{10, 20, 30};

R_array[1] = new int[]{40, 50};

R_array[2] = new int[]{60};

Using_for_loop(R_array);//calling method to print array elements using for loop

Using_for_each(R_array); //calling method to print array elements using for-each loop

Using_array_class(R_array); //calling method to print array elements using Array class

}//end of main method

}//end of Two_D_Ragged class

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education