menu

Java Basic Programs for Beginners

Java Basic Programs for Beginners - Important Points


11. Which of the following is not a control structure in Java?

A. if

B. for

C. switch

D. call

Discuss Work Space

Answer: option d

Explanation:

call is not a control structure in JavIt is not a keyword or part of the language syntax.

12.

What is the output of the following program?

public class Main {
public static void main(String[] args) {
int x = 5;
int y = 2;
int z = x / y;
System.out.println(z);
 }
}

A. 2.5

B. 2

C. 3

D. 5

Discuss Work Space

Answer: option b

Explanation:

The / operator performs integer division when both operands are integers, so the result is 2 in this case.

13.

What is the output of the following program?

public class Main {
public static void main(String[] args) {
int x = 5;
int y = 2;
System.out.println(x > y && y < x);
 }
}

A. 1

B. 0

C. Compile error

D. Runtime error

Discuss Work Space

Answer: option a

Explanation:

The && operator performs logical AND on the two operands, which is true in this case.

14. Which of the following is a valid way to declare and initialize an array of integers in Java?

A. int[] arr = new int[5];

B. int arr[5] = {1, 2, 3, 4, 5};

C. int[] arr = {1, 2, 3, 4, 5};

D. int arr[] = new int[]{1, 2, 3, 4, 5};

Discuss Work Space

Answer: option c

Explanation:

Option C is a valid way to declare and initialize an array of integers in Java.

15.

What is the output of the following program?

public class Main {
public static void main(String[] args) {
int x = 5;
int y = 2;
System.out.println(x > y || y < x);
 }
}

A. 1

B. 0

C. Compile error

D. Runtime error

Discuss Work Space

Answer: option a

Explanation:

The || operator performs logical OR on the two operands, which is true in this case.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now