Hello Programmers, In this post, you will know how to solve the Java Loops II HackerRank Solution. This problem is a part of the HackerRank Java Programming Series.
One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.
Java Loops II HackerRank Solutions
Problem
Problem Statement Link :-
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 HackerRank Solutions
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 BrokenProgrammers. This tutorial is only for Educational and Learning purposes.