Assignment #88 and Adding with a for loop
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Adding with a for loop
///File Name: AddingFor.java
///Date Finished: 11/4/15
import java.util.Scanner;
public class AddingFor
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.print( "Number: " );
int x = keyboard.nextInt();
System.out.println();
int s = 0;
for ( int n = 1; n <= x; n++ )
{
System.out.print(n + " ");
s = s + n;
}
System.out.println( "\nThe sum is " + s );
}
}
Picture of the output