wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java program 1 Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What does the command-line argument <N> represent in this program?

a)

a) The number of matrices

b)

b) The order (size) of the matrix

c)

c) The maximum value of matrix elements

d)

d) The number of rows only

2.

Which class is used to generate random numbers in the program?

a)

a) Math

b)

b) Random

c)

c) Scanner

d)

d) Utility

3.

Which statement correctly describes rand.nextInt(10) in this program?

a)

a) Generates numbers from 0 to 10

b)

b) Generates numbers from 1 to 10

c)

c) Generates numbers from 0 to 9

d)

d) Generates numbers randomly without a limit

4.

What ensures that both matrices are of the same size for addition?

a)

a) User input validation

b)

b) Same value of N used to generate both matrices

c)

c) Try-catch block

d)

d) Java compiler automatically checks

5.

Which modifier makes the helper methods accessible without creating an object?

a)

a) private

b)

b) static

c)

c) public

d)

d) final

6.

Which function generates the matrices in this program?

a)

a) addMatrices()

b)

b) generateRandomMatrix()

c)

c) printMatrix()

d)

d) main()

7.

Which function is responsible for displaying matrices?

a)

a) addMatrices()

b)

b) generateRandomMatrix()

c)

c) printMatrix()

d)

d) main()

8.

Which package does the Random class belong to?

a)
b)

b) java.util

c)

c) java.lang

d)

d) java.random

9.

Why is Integer.parseInt(args[0]) used?

a)

a) To convert a string argument into an integer

b)

b) To generate a random number

c)

c) To parse an integer into a string

d)

d) To check if N is positive

10.

What type of loop is used for matrix traversal in the program?

a)

a) While loop

b)

b) For loop

c)

c) Do-while loop

d)

d) Enhanced for-each loop