Workbook 6.14
From the Java Bootcamp Resources
, launch Workbook 6.14
.
Task 1
This function returns a random number between 0 and 99. Copy it into your class.
public static int randomNumber() {
double randomNumber = Math.random()*100;
return (int)randomNumber;
}
Task 2
Write a function that prints the contents of an int[][]
array.
/** * Function name: print2DArray * @param array ( int[][] ) * * * * * * */
The function uses a nested loop. The inner loop prints each row in one line.
/** * Function name: print2DArray * @param array ( int[][] ) * * Inside the function: * 1. Nested loop: * - Inner Loop: System.out.print(array[i][j] + " "); * */
After the inner loop runs to completion, print a new line.
/** * Function name: print2DArray * @param array ( int[][] ) * * Inside the function: * 1. Nested loop: * - Inner Loop: System.out.print(array[i][j] + " "); * - After the Inner Loop Completes: System.out.print("\n"); */
Call print2DArray
for the following array.
int[][] array = { {48, 56, 56, 76, 0, 81, 51, 81, 99, 70}, {38, 52, 73, 6, 10, 56, 1, 71, 47, 9}, {85, 35, 47, 98, 91, 25, 69, 52, 2, 93} };
Result
Delete the array if you achieve the result.
Task 3
Create a 2D array with 100 rows and 10 columns. Then call print2DArray
.
Task 4
Use a nested loop to populate the array with random numbers before calling: print2DArray
.
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.
Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer
Feedback Summary
4.7
43 students
5
91%
4
2%
3
0%
2
0%
1
7%
Written Reviews
There are no written reviews yet.