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.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Java
  3. Introduction
  4. Java Loops II
  5. Discussions

Java Loops II

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 2105 Discussions, By:

votes

Please Login in order to post a comment

  • sauravdx007 5 years ago+ 0 comments

    I am not getting the question., Can anyone please explain what I need to do?

    244|
    Permalink
  • steveperkins 4 years ago+ 0 comments

    This is an absolute joke. My code worked on the first try, but the exercise was:

    5% - Demonstrating the ability to write a two-level nested "for" loop in Java.

    95% - Getting your mind back into the mode of undergraduate algebra, and deciphering this ridiciously contrived number series.

    For this website to have any meaningful value at all, that emphasis should really be the reverse.

    118|
    Permalink
  • sharmatushar124 4 years ago+ 0 comments

    Guys, done without creating another object please checkout

    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();
                
                for(int j = 0; j < n; j++){
                    a = a + (int)Math.pow(2,j)*b;
                    System.out.print(a + " ");
                }
                System.out.println("");
            }
            in.close();
    
        }
    }
    
    67|
    Permalink
  • RodneyShag 4 years ago+ 0 comments

    Java solution - passes 100% of test cases

    If using Math.pow(), make sure you cast it to an integer since it returns a double.

    import java.util.Scanner;
    
    class Solution{
        public static void main(String [] args) {
            Scanner scan = new Scanner(System.in);
            int t = scan.nextInt();
            for (int i = 0; i < t; i++) {
                int a = scan.nextInt();
                int b = scan.nextInt();
                int n = scan.nextInt();
                
                for (int j = 0; j < n; j++) {
                    a += b * (int) Math.pow(2, j);
                    System.out.print(a + " ");
                }
                System.out.println();
            }
            scan.close();
        }
    }
    

    From my HackerRank Java solutions.

    20|
    Permalink
  • faizjaved 4 years ago+ 0 comments
    class Solution{
        public static void main(String []argh){
            Scanner in = new Scanner(System.in);
            int q=in.nextInt();
            for(int i=0;i<q;i++){
                
                int a = in.nextInt();
                int b = in.nextInt();
                int n = in.nextInt();
                for(int j=0;j<n;j++) {
                    a+=b;
                    System.out.print(a + " ");
                    b*=2;
                }
                System.out.println();
            }
            in.close();
        }
    }
    
    12|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature