Page 395 - ComputerScience_Class_11
P. 395
2. Write a Java program to create an array of integers and calculate the sum and average of the array elements. Display the results
in the following format:
Array Elements: 10 20 30 40 50
Sum: 150
Average: 30.0
3. Write a Java program to create a 2D array and find the highest value in each row. Display the results in the following format:
Input:
10, 20, 30
15, 25, 5
40, 50, 60
Output:
Row 1: Highest: 30
Row 2: Highest 25
Row 3: Highest 60
4. Write a Java program to find the missing number in an array containing distinct integers in the range from 1 to N. The array has
one number missing. The output should be the missing number.
Input:
Array: [1, 2, 3, 5, 6]
Output:
The missing number is 4.
G. Find the output of the following programs:
1. public class MultiDimensionalArray {
public static void main(String args[]) {
int[][] arr = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
System.out.println(arr[1][1]);
}
}
2. import java.util.Scanner;
public class SumAndAverage
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int[] marks = {45, 65, 85, 70, 90}; // Fixed input
int sum = 0;
double avg;
for (int i = 0; i < 5; i++) {
sum += marks[i];
}
avg = sum / 5.0;
System.out.println("Total marks: " + sum);
System.out.println("Average marks: " + avg);
}
}
Arrays 393

