wRITE A java PROGRAM TO FIND THE SUM OF SERIES TILL N
1+2+3+4+5+6+N
Answers
Answered by
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!!!!!!!!!!!!!!!!!!
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
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)
}
}
{
public void disp(int n)
{
int s=0;
for(int i=1;i<=n;i++)
{
s=s+i;
}
System.out.println(s)
}
}
Similar questions