- Home
- Java Pattern Programs
Write a program in Java to display the following pattern: 1
Java Pattern Programs
Write a program in Java to display the following pattern:
1
9 25 49
81 121 169 225 289
Answer
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1, j = 1; j <= 5; i = i * 9, j += 2) {
System.out.print(i + " ");
int t = (int)Math.sqrt(i) + 2;
for (int k = 1; k < j; k++) {
System.out.print((t * t) + " ");
t += 2;
}
System.out.println();
}
}
}