Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In which sequence are the lines of the Cubes.java program in Section 5.2 execute

ID: 3684635 • Letter: I

Question

In which sequence are the lines of the Cubes.java program in Section 5.2 executed, starting with the first line of main?

(just the line numbers)

A cube with side length 2 has volume 8

A cube with side length 10 has volume 1000

section_2/Cubes.java 1  
  /**  
2  
     This program computes the volumes of two cubes.  
3  
  */  
4  
  public class Cubes  
5  
  {  
6  
     public static void main(String[] args)  
7  
     {  
8  
        double result1 = cubeVolume(2);  
9  
        double result2 = cubeVolume(10);  
10  
        System.out.println("A cube with side length 2 has volume " + result1);  
11  
        System.out.println("A cube with side length 10 has volume " + result2);  
12  
     }  
13   14  
     /**  
15  
        Computes the volume of a cube.  
16  
       @param sideLength the side length of the cube  
17  
       @return the volume  
18  
     */  
19  
     public static double cubeVolume(double sideLength)  
20  
     {  
21  
        double volume = sideLength * sideLength * sideLength;  
22  
        return volume;  
23  
     }  
24  
  }  

Explanation / Answer

Here in the above program in main

1)we create a variable name result1,double data type and initialize the value by calling cubeVolume(2).i.e the complier search for cubeVolume() method and finds in line no 19 and executes 21,22 lines.

2) we create a variable name result2,double data type and initialize the value by calling cubeVolume(10).i.e the complier again search for cubeVolume() method and finds in line no 19 and executes 21,22 lines.

3)then prints the values

The execution of code as follows

21

22

8

21

22

9

10

11