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%..

Recommended Answers

All 3 Replies

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

thanks.. you really help me alot.. :))

Please don't forget to mark your threads as "solved" if/when you get the answer you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.