Computer Science, asked by pratyush112, 1 year ago

How to do square of natural number 1+4+9+16+25.......n terms
In java
plz show working

Answers

Answered by aakarsh09
2
import java.util.*;
class square
{
public static void main( String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter any number");
int n=sc.nextInt();
int sq=0;
for(int a=1; a<=n;a++)
{
sq=a*a;
System.out.println(sq)
}
}

pratyush112: sorry
aakarsh09: follow me if you want to ask more java programs
Similar questions