0% found this document useful (0 votes)
3 views4 pages

Test 2 Java CT

The document contains 15 multiple-choice questions (MCQs) related to Java programming, covering topics such as data types, operators, and methods. Additionally, it includes 3 code-based questions that require writing Java programs for checking even or odd numbers, calculating simple interest, and greeting a user based on their full name. Each MCQ is worth 1 mark, while the code questions are worth 5 marks each.

Uploaded by

nilbarua51
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Test 2 Java CT

The document contains 15 multiple-choice questions (MCQs) related to Java programming, covering topics such as data types, operators, and methods. Additionally, it includes 3 code-based questions that require writing Java programs for checking even or odd numbers, calculating simple interest, and greeting a user based on their full name. Each MCQ is worth 1 mark, while the code questions are worth 5 marks each.

Uploaded by

nilbarua51
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

15 MCQ Questions (1 mark each)

Choose the correct option for each of the following questions.

1. Which of the following is not a primitive data type in Java?


A) int
B) float
C) boolean
D) String

2. What is the default value of a boolean variable in Java?


A) true
B) false
C) 0
D) null

3. The operator used for comparison in Java is:


A) =
B) ==
C) :=
D) ===

4. The value of Math.pow(2, 3) is:


A) 5
B) 6
C) 8
D) 9

5. What does the charAt() method return?


A) A string
B) A character at a specific index
C) Index of a character
D) ASCII code
6. Which keyword is used to create an object in Java?
A) create
B) new
C) class
D) object

7. Java was developed by:


A) Microsoft
B) Apple
C) Oracle
D) Sun Microsystems

8. Which of these is a valid variable name in Java?


A) 9score
B) class
C) _value
D) public

9. The result of 10 % 3 in Java is:


A) 3
B) 1
C) 0
D) 10

10. What is the purpose of the break statement in Java?


A) Stop the program
B) Exit a loop or switch-case
C) Skip current iteration
D) None of the above

11. What will System.out.println("A" + 10); print?


A) A10
B) A + 10
C) Error
D) 65 + 10
12. The method used to get input from the user in Java is:
A) nextInput()
B) input()
C) Scanner.next()
D) read()

13. Which of the following loops is entry-controlled?


A) do-while
B) while
C) infinite loop
D) None

14. The output of System.out.println(4 + 5 * 2); is:


A) 18
B) 14
C) 19
D) 13

15. Which method returns the length of a string?


A) size()
B) getLength()
C) length()
D) strLength()
3 Code-Based Questions (5 marks each)

Code Question 1: Even or Odd


Write a Java program to accept an integer from the user and check whether it is even or
odd.

Expected Output Example:


Enter a number: 6
It is Even.

Code Question 2: Simple Interest Calculator


Write a Java program to calculate Simple Interest using the formula:
Simple Interest = (Principal × Rate × Time) / 100
Accept Principal, Rate, and Time from the user.

Code Question 3: Name and Greeting


Write a Java program that accepts a full name (first name and last name) from the user
and performs the following:
Displays the full name in uppercase.
Displays the first character of the first name.
Prints a welcome message in this format:
Hello, [Name]! Welcome to Java Class test.

Tip: Use Scanner, toUpperCase(), and charAt() methods.

You might also like