Computer Science, asked by asha82262gmailcom, 2 months ago

java program to find a series 2,-4,6,-8 to n terms​

Answers

Answered by aditya1457
0

Print Series 2, -4, 6, -8,………n terms in Java

public class Series.

public static void main(String args[]) {

int c, i = 2, n; // c for counter, i for even nos.

System.out.print("\n");

for (c = 1; c <= n; c++, i += 2) //to generate n terms of the series.

if (i % 4 == 0) {

} else {

2 -4 6 -8 10 -12 14 -16 18 -20.

Answered by atrs7391
0

/*

Project Type: Brainly Answer

Date Created: 10-02-2021

Date Edited Last Time: ---NIL---

Question Link: https://brainly.in/question/34957902

Question: Java program to generate a series 2,-4,6,-8 up to N terms.

Program Created By: atrs7391

Programming Language: Java

Language version (When program created or last edited): jdk-15.0.2

*/

package Brainly_Answers;

import java.util.Scanner;

public class Series {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       System.out.println("Enter value of N: ");

       int n = sc.nextInt();

       int v = 0;

       for (int i = 1; i <= n; i++) {

           v = v-2;

           if (i%2==0) {

               System.out.print(v+" ");

           }

           else {

               System.out.print(Math.abs(v)+" ");

           }

       }

   }

}

Similar questions