Assignment #88 and Adding Values with a For Loop

Code

    /// Name: Brendan Baird
    /// Period: 6
    /// Program Name: Adding Values with a For Loop
    /// File Name: AddValFor.java
    /// Date Finished: 12/10/2015
    
    import java.util.Scanner;

    public class AddValFor
    {
        public static void main(String[] args)
        {
            Scanner kb = new Scanner(System.in);
            
            int maxNum;
            int sumNum = 0;
            
            System.out.print("Number: ");
            maxNum = kb.nextInt();
            
            System.out.println();
            
            for ( int i = 1; i <= maxNum; i++ )
            {
                System.out.print(i + " ");
                sumNum = sumNum + i;
            }
            
            System.out.println("\nThe sum is " + sumNum + ".");
        }
    }
    

Picture of the output

Assignment 88