wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA EXAM

Total questions: 25

Worksheet time: 1hrs 1mins

Name
Class
Date
1.

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.45

    Enter 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)

4 lines
2.

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

4 lines
3.

What is the Output?

a)

High Sales Total: 5500

b)

High Sales Total: 2500

c)

High Sales Total: 3000

d)

High Sales Total: 7000

4.

What is the Output?

a)

800

b)

1500

c)

1200

d)

500

5.

What will be printed?

a)

6 12 18

b)

2 4 6

c)

3 6 9

d)

9 18 27

6.

What is the Missing Part?

a)

sum += temps[i];

b)

sum = i + temps[i];

c)

temps[i] = sum;

d)

verage = sum + temps.length;

7.

Find the Error, What will happen when you run the code?

a)

Prints all values correctly

b)

Compilation error

c)

Runtime error: ArrayIndexOutOfBoundsException

d)

Infinite loop

8.

What is Missing to Make this Work?

a)

times[i] = i + 10;

b)

times[i] = (i + 1) * 10;

c)

imes[i] = 10 * i;

d)

times[i] = 10 + i;

9.

Fill in the blank to declare an array of 5 integers in Java:

int[] numbers = new int[ (a)   ];

10.

Fill in the blank to complete the loop that prints all elements in an array:

(a)  

11.

Fill in the blank to sum all elements in the array:

(a)  

12.

Complete the code to find the largest number in the array:

(a)  

13.

Fill in the blank to fix this array declaration error:

(a)  

14.

Identify the missing code to avoid infinite loop:

(a)  

15.

Fill in the missing condition to prevent accessing an invalid index:

(a)  

16.

Fix the bug in this array iteration: Write your new Code

4 lines
17.

Fill in the blank to copy values from one array to another:

4 lines
18.

What will be the output of the following code?

a)

9

b)

6

c)

15

d)

5

19.

Which line has the error in the following code?

a)

int[] marks = new int[5];

b)

for (int i = 0; i <= 5; i++)

c)

marks[i] = i * 2;

d)

No error

20.

What is the output?

a)

4

b)

3

c)

2

d)

1

21.

Which of the following correctly prints all elements in reverse?

a)

b)

c)

d)

22.

Which code correctly counts the number of even numbers in the array?

a)

b)

c)

d)

23.

FILL IN THE BLANKS

(a)  

24.

FILL IN THE BLANKS

(a)  

25.

FILL IN THE BLANKS

(a)