write series code 1,4,9,16.......n terms
import java.util.*; class NumberExample { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter value of n: "); int n=input.nextInt(); int sum=0; int m=0; for(int i=1;i<=n;i++){ m=i*i; sum+=m; System.out.print(m+" "); } System.out.println(); System.out.println("Sum of series: "+sum); } }
Ads