WorksheetsJAVA EXAM
Total questions: 25
Worksheet time: 1hrs 1mins
Create JAVA Program
🎯 Problem Requirements:
Write a Java program that:
Stores daily expenses for 30 days in an array
Uses a for loop to input each day's expense
Calculates and displays the total and average spending
Identifies the day with the highest and lowest expense
EXAMPLE OUTPUT
Enter expense for day 1: $23.45Enter expense for day 2: $15.90
...
Enter expense for day 30: $33.25
=== EXPENSE SUMMARY ===
Total Expense: $725.67
Average Daily Expense: $24.19
Highest Expense: Day 15 ($52.75)
Lowest Expense: Day 3 ($10.00)
Creaet a Java Program
Task Time Analyzer
Your software team logs how long (in minutes) each of 10 tasks took to complete. Build a tool that analyzes this data.
🎯 Program Goals:
Input task durations using a for loop
Calculate total and average task time
Identify tasks that took more than average
Find the longest and shortest task
Sample Output
Enter time for Task 1: 25...
Enter time for Task 10: 35
Total Time: 310 minutes
Average Time: 31.0 minutes
Longest Task: Task 4 (45 minutes)
Shortest Task: Task 7 (22 minutes)
Tasks Above Average: Task 4, Task 6, Task 10
What is the Output?
High Sales Total: 5500
High Sales Total: 2500
High Sales Total: 3000
High Sales Total: 7000
What is the Output?
800
1500
1200
500
What will be printed?
6 12 18
2 4 6
3 6 9
9 18 27
What is the Missing Part?
sum += temps[i];
sum = i + temps[i];
temps[i] = sum;
verage = sum + temps.length;
Find the Error, What will happen when you run the code?
Prints all values correctly
Compilation error
Runtime error: ArrayIndexOutOfBoundsException
Infinite loop
What is Missing to Make this Work?
times[i] = i + 10;
times[i] = (i + 1) * 10;
imes[i] = 10 * i;
times[i] = 10 + i;
Fill in the blank to declare an array of 5 integers in Java:
int[] numbers = new int[ (a) ];
Fill in the blank to complete the loop that prints all elements in an array:
(a)
Fill in the blank to sum all elements in the array:
(a)
Complete the code to find the largest number in the array:
(a)
Fill in the blank to fix this array declaration error:
(a)
Identify the missing code to avoid infinite loop:
(a)
Fill in the missing condition to prevent accessing an invalid index:
(a)
Fix the bug in this array iteration: Write your new Code
Fill in the blank to copy values from one array to another:
What will be the output of the following code?
9
6
15
5
Which line has the error in the following code?
int[] marks = new int[5];
for (int i = 0; i <= 5; i++)
marks[i] = i * 2;
No error
What is the output?
4
3
2
1
Which of the following correctly prints all elements in reverse?
Which code correctly counts the number of even numbers in the array?
FILL IN THE BLANKS
(a)
FILL IN THE BLANKS
(a)
FILL IN THE BLANKS
(a)
