Computer Science, asked by Ronald11, 1 year ago

wRITE A java PROGRAM TO FIND THE SUM OF SERIES TILL N

1+2+3+4+5+6+N

Answers

Answered by anuj
0
HEYA friend ,


import java.io.*;
class series
{
  public static void main()throws IOException
    {
         DataInputStream ak = new DataInputStream(System.in);

           System.out.println("Enter a number till u want sum");

             int n=Integer.parseInt(ak.readLine());
               
              int sum=0;
  
           for(int i=1;i<=n;i++)
           {
             sum = sum+ i;
            }
      System.out.println("SUM IS "+sum);
   }
}
       


HOPE IT HELPS!!!!!!!!!!!!!!!!!!

Ronald11: ryt!
Answered by shirsha143
1
class abc
{
public void disp(int n)
{
int s=0;
for(int i=1;i<=n;i++)
{
s=s+i;
}
System.out.println(s)
}
}

anuj: ryt
Ronald11: yup
Ronald11: but i needed till n
Ronald11: np
shirsha143: I have edited it
shirsha143: now it will give what u need
Ronald11: nyc
Similar questions