Assignment #88: Adding With a For Loop

Code

import java.util.Scanner;

public class ForAdding {

    public static void main (String[] args) {
    
        int count;
        int total = 0;
        
        Scanner kb = new Scanner(System.in);
    
        System.out.println("Give me a number and I will sum it up with every number before it.");
        count = kb.nextInt();
        
        for (int n = 0; n <= count; n = n + 1) {
        
            total = total + n;
            
        }
        
        System.out.println("The total is " + total + " .");
        
    }

}
    

Picture of the output