0

So, im making a program in which whenever a button is clicked 3 is added to an integer called Score so that if the button is clicked 2 times score will be 6.I made the score int final int with value of 0.

Ok the syntax i added was

  • To add 3: Viewablescore[0] =+ 3;
  • For console System.out.println(Viewablescore);
  • for JFrame label2.setText(String.valueOf(Viewablescore));

I wanted to print the result on both console and in the Jframe, but i was given with [I@563bf420. The program ran successfully. What should i do

  • The other way around. `+=`, not `=+`. This way to avoid cinfusion with setting the value to `+3` (which is what your code does). – Ole V.V. Mar 28 '23 at 17:24
  • You said your int is final, You cannot change the value of a final variable. I suggest you read about [variables](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html). – Cardinal System Mar 28 '23 at 17:25
  • 1
    Are you using an array but only using element 0 of the array? What’s the point of using an array, then? – Ole V.V. Mar 28 '23 at 17:29
  • Cardinal Hey! i tried using a local var but rather than adding it it simply just printed the value of the button i clicked – M.Ibrahim Abdullah Mar 29 '23 at 08:11
  • @OleV.V. What should i do then? – M.Ibrahim Abdullah Mar 29 '23 at 08:12
  • Assuming that you have told us all that you want to obtain and your code isn’t multi-threaded, then just use a (non-final) `int` variable and add 3 to it when the button is clicked. Then it is trivial to print it. And still use `String.valueOf()` to put it in the label. – Ole V.V. Mar 29 '23 at 08:30

0 Answers0