Computer Science, asked by NAVSTERS, 11 months ago

Java looping (they ar squares)
How to print this pattern???​

Attachments:

Answers

Answered by anishasa
0

Explanation:

Pattern:

1 squared = 1, 1 + 3 = 4

4 squared = 16, 4 + 6 = 10

10 squared = 100, 10 + 3 = 13

13 squared = 169, 13 + 6 = 19 and repeats..

Program:

import java.util.Scanner;

Scanner sc=new Scanner(System.in);

System.out.println("Enter the Number:");

       int rows=sc.nextInt();

System.out.println("The Pattern:");

int i=1,b=2;

 while(i<rows){

 System.out.print((int)Math.pow(i,b)+" ");

i=i+3;

}

}

Math.pow() is used to calculate a number raise to the power of some other number.

Output:

Enter the Number:

45

The Pattern:

1 16 49 100 169 256 361 484 625 784 961 1156 1369 1600 1849

Similar questions