Sum of n Numbers

 Sum of n Numbers

Sum of n Numbers

Problem Description


Write a program that reads a positive integer, n, from the user and then displays the sum of all of the integers from 1

Logic Test Case 1


Input (stdin)

5


Expected Output


15

Logic Test Case 2


Input (stdin)

10


Expected Output


55



Code Area

import java.io.*;


import java.util.Scanner;


public class TestClass {



    public static void main(String[] args) {

    int num, count, total=0;

        Scanner scan = new Scanner(System.in);

        num = scan.nextInt();

        scan.close();


        for(count = 1; count <= num; count++){


            total = total + count;


        }




        System.out.print(""+total);

    }


}

Post a comment

0 Comments