KnowledgeBoat Logo

Java Series Programs

Write a program in Java to print the following series:

3, 6, 12, 24, 48, ….. to n

Java

Java Iterative Stmts

ICSE

8 Likes

Answer

import java.util.Scanner;

public class KboatSeries
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter n: ");
        int n = in.nextInt();
        int t = 3;
        for (int i = 1; i <= n; i++) {
            System.out.print(t + " ");
            t *= 2;
        }
    }
}

Output

BlueJ output of Write a program in Java to print the following series: 3, 6, 12, 24, 48, ….. to n

Answered By

2 Likes