Assignment # 88 and Adding For Loop
Code
/// Name: Tommy Oyuntseren
/// Period: 7
/// Program Name: AddingForLoop
/// File Name: AddingForLoop.java
/// Date: 3/1/2016
import java.util.Scanner;
public class AddingForLoop
{
public static void main(String[] args)
{
Scanner kb=new Scanner(System.in);
int total=0;
System.out.print("Number: ");
int number= kb.nextInt();
for (int n=1; n<=number; n=n+1)
{
System.out.print(n +" ");
total=n+total;
}
System.out.println("The sum is " + total);
}
}
Picture of the output