Question:
Consider the following program:
public class DataTypesExample {
public static void main(String[] args) {
int numStudents = 35;
double averageScore = 83.45;
char grade = 'A';
boolean passed = true;
System.out.println("Number of students in the class: " + numStudents);
System.out.println("Average score in the class: " + averageScore);
System.out.println("Grade of the student: " + grade);
System.out.println("Did the student pass the class? " + passed);
}
}
What will be the output of the above program?
Number of students in the class: 35 Average score in the class: 83.45 Grade of the student: A Did the student pass the class? true
Number of students in the class: 35.0 Average score in the class: 83.45 Grade of the student: A Did the student pass the class? true
Number of students in the class: 35 Average score in the class: 83.45 Grade of the student: 65 Did the student pass the class? true
Number of students in the class: 35 Average score in the class: 83.45 Grade of the student: A Did the student pass the class? false
None of the above
Answer:
The correct answer is option 1:
Number of students in the class: 35 Average score in the class: 83.45 Grade of the student: A Did the student pass the class? true
Explanation:
numStudents
is assigned the value 35, which is an int data type.averageScore
is assigned the value 83.45, which is a double data type.grade
is assigned the value 'A', which is a char data type.passed
is assigned the value true, which is a boolean data type.In the program, we use the System.out.println()
method to print the values of these variables along with some additional text. The output will be displayed as follows:
Number of students in the class: 35
Average score in the class: 83.45
Grade of the student: A
Did the student pass the class? true
Therefore, option 1 is the correct answer.