menu

Java Basic Programs for Beginners

Java Basic Programs for Beginners - Important Points


6.

What is the output of the following program?

public class Main {
public static void main(String[] args) {
String str = "Hello World";
System.out.println(str.charAt(6));
 }
}

A. H

B. e

C. W

D. o

Discuss Work Space

Answer: option c

Explanation:

The charAt() method of the String class returns the character at the specified index, starting from 0.

7.

What is the output of the following program?

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

A. 1

B. 0

C. Compile error

D. Runtime error

Discuss Work Space

Answer: option b

Explanation:

The expression x == y compares the values of x and y for equality, which is false in this case.

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

A. int

B. boolean

C. string

D. double

Discuss Work Space

Answer: option c

Explanation:

string is not a primitive data type in JavIt is a class in the Java standard library.

9.

What is the output of the following program?

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

A. 1

B. 0

C. Compile error

D. Runtime error

Discuss Work Space

Answer: option a

Explanation:

The expression x < y compares the values of x and y for inequality, which is true in this case.

10.

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);
 }
}

A. 1

B. 2

C. 3

D. 5

Discuss Work Space

Answer: option a

Explanation:

The % operator returns the remainder of the division of the two operands, which is 1 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