Java Loops II

  • + 2 comments

    Yes.This is correct. But I have one question... In the series we can see evey value is multiply by b.(either first a also).But in your code I can't see that. But your one gives correct answer. Can you please explain that for me?

    I used this and this gives wrong answerI can't realize why it is wrong???

    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 q1=0;q1<t;q1++){
                
                int a = in.nextInt();
                int b = in.nextInt();
                int n = in.nextInt();
                int ans=a+1*b;   
                    for(int j=0;j<n;j++){
                        int x=2^j*b;
                        ans+=x;
                       System.out.print(ans+" ");
                        
                       
                        
                     }
                 
                System.out.println();
            }
    
            
            in.close();
        }
    }