Java Loops II

  • + 0 comments

    Solución en Java

    import java.io.; import java.util.;

    public class Solution { public static String calculo(int q, ArrayList> listas){ String respuesta = "";

        int Serie = 0;
    
        for (int i = 0; i < q; i++) {
            int expresionfija = listas.get(i).get(0) + ((int) Math.pow(2, 0) * listas.get(i).get(1));
    
            respuesta= String.valueOf(expresionfija);
    
            for (int j = 1; j < listas.get(i).get(2); j++) {
                Serie = expresionfija + ((int) Math.pow(2, j) * listas.get(i).get(1));
                expresionfija = Serie;
                respuesta += " "+ String.valueOf(Serie);
            }
            System.out.println(respuesta);
        }
    
         return respuesta;
    }
    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    
        Scanner scanner = new Scanner(System.in);
        int q = scanner.nextInt();
        scanner.nextLine();
    
        ArrayList <ArrayList<Integer>> listas = new ArrayList(); 
        for (int i = 0; i < q; i++) {
            ArrayList <Integer>listainterna = new ArrayList();
            for (int j = 0; j < 3; j++) {
                listainterna.add(scanner.nextInt());
            }
            listas.add(listainterna);
        } 
    
        scanner.close();
    
        calculo(q ,listas);
    }
    

    }