0
System.out.println("\t \t \tYou got " + (cor/10*50+50) + "%");

help me with this code.. i didn't get what's supposed to be the percentage.. what's wrong with it?.. i got 3 for cor and i should have 65% but i just get 50%..

2
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

It's integer arithmetic, normal maths priority, so
cor/10 = 0 (would be 0.3333, but this is integer math)
0*50 = 0
0+50 = 50

To fix it, change the order of your expression so the * is done before the /, ie
cor*50 = 150
150/10 = 15
15+50 = 65

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.