F
F
Freijer2022-04-06 08:37:28
Java
Freijer, 2022-04-06 08:37:28

How to create a variable increment counter?

Hello.

There is a variable, conditionally When the condition is triggered, the variable is incremented by a value from the range from 1 to 15. How to make a variable increment counter? Those. I only need to count the number of increments. Or change the variable to only 1, regardless of the incoming number from the range (limiting the range to 1 is not an option). int sc = 0;


Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2022-04-06
@xez

Make another variable, say counterSC, which is incremented by one each time sc is incremented.

M
Maly, 2022-04-06
@maly222

int sc=0;
       button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
        
                 
 sc++;
                        System.out.println(sc);
                            
                        if(sc==15){
                            sc=0;
                        System.out.println(0);
                            
                        }
                  }
        });

Do you need something like this or something else?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question