Assignment 88, Adding Values With a For Loop
Code
///Name: Stella Koliavas
///Period: 5
///File Name: Adding2.java
///Date Finshed: 2/23/16
import java.util.Scanner;
public class Adding2
{
public static void main(String[] args)
{
Scanner siri = new Scanner(System.in);
int x, sum = 0;
System.out.print("Number: ");
x = siri.nextInt();
for ( int n = 0 ; n <= x ; n = n +1 )
{
sum = sum + n;
System.out.println((n));
}
System.out.println("The sum of all the numbers is "+ sum+ ".");
}
}
Picture of the output