Java Loops II

Sort by

recency

|

3239 Discussions

|

  • + 0 comments

    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

  • + 0 comments
    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();
            for(int j=0; j<n;j++){
                double sum=0;
                for(double k=0;k<=j;k++){
                    double d= 2.0;
                    sum= sum + Math.pow(d,k)*b;
                }
                
                int myInt = (int) (a+sum);
                System.out.print(myInt);
                System.out.print(' ');
                
            }
            System.out.println();
            
            
            }
            
            
            in.close();
        }
    }
    
  • + 0 comments

    Java is such a versatile and powerful programming language! Whether you're building web applications, mobile apps, or enterprise-level software, its reliability and cross-platform capabilities make it a solid choice for developers at any level. 11xplay new ID Signup

  • + 0 comments
    import java.util.*;
    import java.io.*;
    import java.lang.Math;
    
    class Main{
        public static void main(String []argh){
            Scanner in = new Scanner(System.in);
            int t=in.nextInt();
            int[] a = new int[t];
            int[] b = new int[t];
            int[] n = new int[t];
            for(int i=0;i<t;i++){
                 a[i] = in.nextInt();
                 b[i] = in.nextInt();
                 n[i] = in.nextInt();
            }
            in.close();
            
            for(int j=0;j<t;j++){
                //.out.println(a[j]+" "+b[j]+" "+n[j]+" ");
                int ans = a[j];
                for(int k=0;k<n[j];k++){
                    ans += (int) Math.pow(2, k)*b[j];
                    System.out.print(ans+" ");
                } 
                System.out.println();
                
            }
        }
    }
    
  • + 1 comment
    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();
                int current_sum = a;
                for (int j = 0; j < n; j++) {
                    current_sum += (int)Math.pow(2, j) * b;
                    System.out.print(current_sum + " ");
                }
                System.out.println();
            }
            in.close();
        }
    }