Assignment #88 and Adding Values With A For Loop

Code

    /// Name: Tim Chuang
/// Period: 7
/// Program Name: Adding Values With A For Loop
/// File Name: AddingValuesWithAForLoop.java
/// Date Finished: 3/4/2016

import java.util.Scanner;

public class AddingValuesWithAForLoop
{
	public static void main( String[] args )
	{
        Scanner keyboard = new Scanner(System.in);
        int number, y;
        y = 0;
        System.out.print("Number: ");
        number = keyboard.nextInt();
        System.out.println();
        for ( int x = 1; x <= number; x = x + 1 )
        {
            y = y + x;
            System.out.print( x + " " );
        }
        System.out.println("The sum is " + y + ".");
    }
}

    

Picture of the output

Assignment 88