WAP in java to print the series
1>1^2 + 2^2 + 3^2 +......................n
Answers
Answered by
1
Heya!!
the program is as follows:-
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*i);
}
System.out.println("SUM IS "+sum);
}
}
HOPE IT HELPS!!!!!!!!!!!!!!!!!!
the program is as follows:-
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*i);
}
System.out.println("SUM IS "+sum);
}
}
HOPE IT HELPS!!!!!!!!!!!!!!!!!!
Similar questions
Social Sciences,
7 months ago
English,
7 months ago
Computer Science,
7 months ago
Social Sciences,
1 year ago