Java · Question 18 · Easy

What will be the output of the following Java program?

public class Main {
    public static void main(String[] args) {
        System.out.println(10 / 3 * 3.0);
    }
}
  1. 10.0
  2. 9.0
  3. 9
  4. 9.999999999999998
Answer and explanation

Answer: B. 9.0

Explanation: 10 / 3 is integer division and gives 3. Multiplying by the double 3.0 gives 9.0, which println shows as 9.0.

Previous: What is the size of the int data type in Java, regardless of the platform? · Next: Which access modifier makes a class member accessible only within the class in…

Practise java

Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.

More java questions

More technical & programming practice

Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge