wap a java program for pattern
Attachments:
Answers
Answered by
0
Program:
import java.util.Scanner;
public class brainly
{
public static void main(String[] args)
{
Scanner scan=new Scanner (System.in);
System.out.print("Enter the value of n: ");
double n=scan.nextInt();
System.out.print("Enter the value of k: ");
double k=scan.nextInt();
double sum=1;
for (int i=1;i<n+1;i++)
{
sum = sum+(Math.pow(-1,i)*Math.pow(k, i));
}
System.out.println(sum);
}
}
Attachments:
Similar questions
History,
2 months ago
Physics,
2 months ago
Social Sciences,
5 months ago
Math,
11 months ago
Math,
11 months ago