#Need to add up the numbers in my parameter

25 messages · Page 1 of 1 (latest)

stray coyote
#

Im doing an assignment where first i need to get an int where it prints all the numbers from 1 to the number. After that I need to add all the numbers it prints but idk how to do that

undone cometBOT
#

This post has been reserved for your question.

Hey @stray coyote! 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.

stray coyote
#
import java.util.Scanner;
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) 
    {
        
        
    }
    
    }
#

thats my code atm

zealous spoke
#

how do you loop over the numbers from 1 to the input

stray coyote
zealous spoke
#

yep

#

so how do you add numbers together

stray coyote
#

uhh

#

x+y; ?

zealous spoke
#

yep

#

so now you need to put that in a variable

#

so you can remember what the previous value was

stray coyote
#

put what in a variable

zealous spoke
stray coyote
#

oh

#

okk

#

ty

#

i lied i have no idea wym

zealous spoke
#

do you know how to make variables

stray coyote
#

yea

zealous spoke
#

yeah you just need that and then you add to that variable for each number

stray coyote
#

OH OK

undone cometBOT
#

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