Assignment #88
Code
/*
jack newsom
period 5
Program AddingWithFor
filename AddingWithFor.java
date completed 10/26/15
*/
import java.util.Scanner;
public class AddingWithFor
{
public static void main( String[] args )
{
Scanner bot = new Scanner(System.in);
int sum = 0;
int counter = 0;
System.out.println("Number: ");
int user = bot.nextInt();
for ( int i = 1; i <= user; i++ )
{
System.out.print( " " + i + " ");
sum = sum + i;
counter++;
}
System.out.println();
System.out.println("The sum is " + sum + ".");
}
}
Picture of the output