please some one solve this java pattern program
Answers
Answer:
The First Program:
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.print("Enter the number of terms: ");
int a= sc.nextInt();
int i = 1;
while (i <= a) {
if (i == 1) {
System.out.print(1 + " ");
} else {
System.out.print((int)(Math.pow(i, 3) - 1) + " ");
}
i++;
}
}
}
The Second Program:
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.print("Enter the number of terms: ");
int a= sc.nextInt();
for (int i = 5; i > 0; i--) {
for (int j = 1; j <= i; j++) {
System.out.print(a-- + "\t");
}
System.out.println();
}
}
}