-1

I am trying to display a JLabel that holds the final points, the number of aliens found in the game and the percentage out of 30 aliens. Whenever I run my program the score/30*100 part just produces 0 instead of the actual percentage. I've tried creating a separate variable called percent with the equation and subbing it into the setText but it still doesn't work. Help?

    sb.scoreLabel.setText("<html> Final Score: <html>" + (score-(incorrect)) + "<html>00<p> You got "
                    + score + "/30 aliens! (<html>" + ((score/30)*100) + "<html>%) <html>" );
Rachel Su
  • 13
  • 3

1 Answers1

-1
((score/30)*100) 

You are using integer math so (score/30) is 0 (assuming score is less than 30).

Instead use:

((score * 100) / 30)
camickr
  • 321,443
  • 19
  • 166
  • 288
  • I see you used my solution in the code you posted for your latest question: https://stackoverflow.com/questions/44359575/how-do-i-create-a-main-menu-for-my-game. Don't forget to "accept" the answer so people know the problem has been solved. – camickr Jun 04 '17 at 23:13