Java Loops II – Hacker Rank Solution Java

Java Loops II Hacker Rank Solution Java 1
Java Loops II – Hacker Rank Solution Java

Problem :

Problem Statement Link :-

Problem Statement


Sample Input :

2
0 2 10
5 3 5

Sample Output :

2 6 14 30 62 126 254 510 1022 2046
8 14 26 50 98


Java Loops II – Hacker Rank Solution Java

import java.util.*;
import java.io.*;
class Solution
{
    public static void main(String []argh)
    {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        {
            int a = in.nextInt();
            int b = in.nextInt();
            int n = in.nextInt();
            // Java Loops II - Hacker Rank Solution Java START
            for (int j = 0; j < n; j++)
            {
                a += b * (int) Math.pow(2, j);
                System.out.print(a + " ");
            }
            System.out.println();
            // Java Loops II - Hacker Rank Solution Java END
        }
        in.close();
    }
}

Disclaimer: The above Problem (Java Loops II) is generated by Hackerrank but the Solution is Provided by Chase2Learn. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the following contact form thank you.

Leave a Comment