Assignment #88
Code
/// Name: Jonathan Stine
/// Period: 5
/// Program name: AddForLoop.java
/// File Name: Adding Values with for loops
/// Date Finished: 3/4/2016 (On the Jewish Calender its the year 5776)
import java.util.Scanner;
public class AddForLoop
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Number: ");
int num = keyboard.nextInt();
int sum=0;
for (int i = 1;i<=num; i++)
{
sum = sum +i;
System.out.print(" "+i);
}
System.out.println("\n The sum is "+sum+".");
}
}
Code Output