WAP to print a series 1, 4, 9, 16, ….. upto 20 terms.

1 year ago
OOP Java

Compile code:

import java.util.Scanner;

public class p8 {
    public static void main(String[] args) {
        Scanner cs = new Scanner(System.in);
        int n=20, i = 1;
        System.out.println("Enter the range of number(Limit):");
        n = cs.nextInt();

        while (i <= n) {
            System.out.print(i * i + " ");
            i++;
        }
        cs.close();
    }
}

 

Output:

0
Dipti KC
Jan 8, 2023
More related questions

Questions Bank

View all Questions