In: Computer Science
I am coding with NetBeans LDE Java.
Write a program that reads a positive integer n , prints all sums from 1 to any integer m 1≤m≤n . For example, if n=100, the output of your program should be
The sum of positive integers from 1 to 1 is 1;
The sum of positive integers from 1 to 2 is 3;
The sum of positive integers from 1 to 3 is 6;
The sum of positive integers from 1 to 4 is 10;
The sum of positive integers from 1 to 5 is 15;
*
*
*
*
The sum of positive integers from 1 to 100 is 5050.
(The program should include a main method, and no tester class is needed)
import java.util.Scanner;
public class Main
{
   public static void main(String[] args)
   {
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   int total=0;
   for(int i=1;i<=n;i++)
   {
   total=total+i;
       System.out.print("The sum of
positive integers from 1 to "+i+" is "+total);  
  
       if(i==n)
       System.out.println(".");
       else
       System.out.println(";");
   }
   }
}