Computer Applications
Write a program in Java to print the following series:
3, 6, 12, 24, 48, ….. to n
Java
Java Iterative Stmts
53 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

Answered By
23 Likes
Related Questions
Give the output of the following program segment. How many times is the loop executed?
for(x=10; x>20;x++) System.out.println(x); System.out.println(x*2);Which of the following are entry controlled loops?
(a) for
(b) while
(c) do..while
(d) switch
- only a
- a and b
- a and c
- c and d
How many times will the following loop execute? Write the output of the code:
int x=10; while (true){ System.out.println(x++ * 2); if(x%3==0) break; }