Write a program in JAVA to print the output of the following series 2 - 4 + 8 - 16 ................ upto n terms.

Answers (1)

// Java Program to print the series 
// 2, 1, 4, 3, 6, 5, …. up to N terms 

import java.util.*; 
import java.lang.*; 
import java.io.*; 

class GFG 
 
// Function to print the series 
static void printPattern(int N) 
 
    
    for (int i = 1; i <= N; i++)  
    
        // Find and print the ith term 
        System.out.print(" "+((i % 2 == 0) ? (i - 1) : (i + 1))); 
     
 
    
// Driver code 
public static void main(String args[]) 
 
    
    // Get the value of N 
    int N = 10; 
    
    // Print the Series 
    printPattern(N); 
    
 
 
 

Preparation Products

Knockout NEET May 2023 (Easy Installments)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 5499/-
Buy Now
Knockout JEE Main April 2021 (One Month)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 14000/- ₹ 4999/-
Buy Now
Knockout NEET Aug 2021 (One Month)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 14000/- ₹ 4999/-
Buy Now
Knockout JEE Main May 2021

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 22999/- ₹ 9999/-
Buy Now
Knockout NEET Aug 2021

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 22999/- ₹ 9999/-
Buy Now
Boost your Preparation for JEE Main with our Foundation Course
 
Exams
Articles
Questions