Assignemnt #88 Adding Values with a For Loop
Code
///Name: Prooz Fereydouni
///Period: 7
///Project Name: Adding Values with a For Loop
///File Name: AVwaFL.java
///Date: 3/3/2016
import java.util.Scanner;
public class AVwaFL
{
public static void main( String[] args)
{
Scanner kb= new Scanner(System.in);
System.out.print("Number: ");
int number = kb.nextInt();
int sum=0;
for (int i=1; i<=number ; i++)
{
sum= sum +i;
System.out.print(i+ " ");
}
System.out.println("");
System.out.println("The sum of the numbers are: "+ sum);
}
}
Picture of the output