Assignment #88 Adding Values with a For Loop
Code
/// Name: Koosha Kimelman
/// Period: 7
/// Program Name: Adding Values with a Foor Loop
/// File Name: AddingForLoop.java
/// Date Completed: 12/11/15
import java.util.Scanner;
public class AddingForLoop {
public static void main(String[] args) throws Exception {
Scanner kb = new Scanner(System.in);
System.out.print("Number: ");
int n = kb.nextInt();
int s = 0;
System.out.println();
for (int x = 1; x <= n; x++) {
System.out.print(x + " ");
s += x;
Thread.sleep(50);
}
System.out.println("\nThe sum is " + s + ".");
}
}
Picture of the output