πŸ“Š JAVA
Q. 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);
}
}
  • (A) 2
  • (B) 0
  • (C) 3
  • (D) 3 D. 2.5
πŸ’¬ Discuss
βœ… Correct Answer: (B) 0

Explanation: 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.

Explanation by: Gopal Sharma
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
85
Total Visits
πŸ“½οΈ
12 mo ago
Published
πŸŽ–οΈ
Gopal Sharma
Publisher
πŸ“ˆ
93%
Success Rate