We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Java
  3. Introduction
  4. Java Loops II
  5. Discussions

Java Loops II

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • _jimmy_
    3 months ago+ 0 comments

    My solution, an easy way

    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();
                
                double prev = a;
                
                for (int j = 0; j < n; j++) {
                    prev += Math.pow(2, j) * b;
                    
                    //System.out.println(a  + " + " + 2 + "**" + j + " * " + b);
                    
                    System.out.print((int) prev + " ");
                }
                
                System.out.println();
            }
            
            in.close();
        }
    }
    
    2|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy