Code
/// Name: Afaf Nabeeha
/// Period: 7
/// Program Name: Adding Values with a For Loop
/// File Name: Values.java
/// Date Finished: 12/20/2015 public class Values
import java.util.Scanner;
public class Values
{
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