#Need a counter for my for loop

15 messages · Page 1 of 1 (latest)

ocean rivet
#

im doing an assignment as a first semester java student and i need a counter for my for loop but idk how to do it

knotty sigilBOT
#

This post has been reserved for your question.

Hey @ocean rivet! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

ocean rivet
#

my for loop is

#
{
        for(int b = 1; b < a ; b++)
            System.out.println(b);
    }
#

the rest of my code is

#
public class Methods {
    
    public static int summer (int[] args)
    {
        Scanner scan = new Scanner(System.in);
    System.out.println("Type one number: ");
    int a=scan.nextInt();
    
    {
        for(int b = 1; b < a ; b++)
            System.out.println(b);
    }
    
    return a;
    }        
    
    public static void upRev (String[] args) 
    
    
    {
    }
    }
quasi ocean
#

What's the counter for?

#

Something like: int count = 0 before your for-loop then inside your for-loop's body after the "println" statement add: "count++;"

knotty sigilBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

ocean rivet
#

The parameter being a

ocean rivet
#

@quasi ocean