Computer Science, asked by swathasingh, 5 months ago

wap a java program for pattern​

Attachments:

Answers

Answered by allysia
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