Lab Sheet 7: Arrays


1D Array Exercises
Question 1: Basic Array Operations
Create a Java program that:
Declares an array of 10 integers
Initializes the array with the following values: {12, 5, 23, 8, 17, 9, 31, 4, 11, 19}
Prints all elements of the array
Calculates and prints the sum of all elements
Finds and prints the largest and smallest elements in the array
Question 2: Array Manipulation
Write a Java program that:
Creates an array to store 8 double values entered by the user
Prints the array in reverse order
Calculates and prints the average of the array elements
Counts and prints how many elements are above the average
Question 3: Student Marks Processing
Develop a program that:
Stores names and marks of 5 students in two separate arrays
Finds and displays the name and mark of the student with the highest score
Finds and displays the name and mark of the student with the lowest score
Calculates and displays the class average
2D Array Exercises
Question 4: Basic Matrix Operations
Create a Java program that:
Declares and initializes a 3x3 integer matrix with values: {{4, 9, 2}, {3, 5, 7}, {8, 1, 6}}
Prints the matrix in proper matrix format (rows and columns)
Calculates and prints the sum of all elements
Finds and prints the largest element in the entire matrix
Calculates and prints the sum of each row separately
Question 5: Matrix Manipulation
Write a Java program that:
Reads a 4x4 integer matrix from user input
Prints the matrix
Creates and prints the transpose of the matrix (rows become columns and vice versa)
Calculates and prints the sum of the main diagonal elements
Question 6: Advanced Matrix Processing
Develop a program that:
Reads a 5x4 integer matrix from user input (4 rows of data)
Calculates the sum of each column
Stores these column sums as the 5th row of the matrix
Prints the complete 5x4 matrix (with the sums row)
Finds and prints the column with the highest sum
Practical Application Questions
Question 7: Temperature Analysis
Create a program that:
Stores daily temperature readings for a week (7 days) in an array
Calculates and displays the average weekly temperature
Identifies and displays the hottest and coldest days of the week
Counts how many days were above the average temperature
Question 8: Inventory Management
Write a program for a store that:
Uses a 2D array to store product information (product ID, quantity, price) for 10 products
Allows the user to input this information
Calculates and displays the total value of each product (quantity × price)
Finds and displays the product with the highest total value
Calculates and displays the total inventory value
Subscribe to my newsletter
Read articles from Arzath Areeff directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Arzath Areeff
Arzath Areeff
I co-founded digizen.lk to promote online safety and critical thinking. Currently, I’m developing an AI app to fight misinformation. As Founder and CEO of ideaGeek.net, I help turn startup dreams into reality, and I share tech insights and travel stories on my YouTube channels, TechNomad and Rz Omar.