HackerRank Java- Loops II




You are given q queries in the form of a, b, and n. For each query, print the series corresponding to the given a, b, and n values as a single line of n space-separated integers.



  1. import java.util.*;
  2. import java.io.*;
  3. class Solution{
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. int t = scan.nextInt();
  7. for (int i = 0; i < t; i++) {
  8. int a = scan.nextInt();
  9. int b = scan.nextInt();
  10. int n = scan.nextInt();
  11. for (int j = 0; j < n; j++) {
  12. a += b * (int) Math.pow(2, j);
  13. System.out.print(a + " ");
  14. }
  15. System.out.println();
  16. }
  17. scan.close();
  18. }
  19. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube