Assignement: #88 Adding Values with a For Loop
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: AddingValues
/// File Name: Addingvalues.java
/// Date Finished: 3/3/2016
import java.util.Scanner;
public class AddingValues
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int number, y;
y = 0;
System.out.println( " Number: " );
number = keyboard.nextInt();
System.out.println();
for ( int x = 1; x <= number; x = x + 1 )
{
y = x + y;
System.out.println( x + " " );
}
System.out.println( " The sum of the numbers is " + y + "." );
}
}
Picture of the output