ExamVeda
Login
Home
Data Types and Variables
?

What will the output of the following program?
public class Test{
      public static void main(String args[]){
            float f = (1 / 4) * 10;
            int i = Math.round(f);
            System.out.println(i);
      }
}

Answer & Solution
Correct Answer: Option B

The result of 1/4 will be zero because integer division is carried out on the operands. If you need to obtain a fractional value you need to use either a float or double literal as in 1F / 4F.

Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Preeti Yadav
Preeti Yadav 5 years ago
Could anyone please explain it why (1/4)=0
Aya Borgoul
Aya Borgoul 5 years ago
There is *10