2020-11-27

Many inputs java

The program asks me to solve the sum of several numbers you enter(1^p+..+n^p), but I don't know how to make the program accept many inputs without create more scanners.

    import java.util.Scanner;
    public class ejercicio3 {
    public static void main(String [] args){
    Scanner entrada = new Scanner(System.in);
        
        int base = entrada.nextInt();
        int exp = entrada.nextInt();
        int suma = 0;
        
        if(base == 0 & exp == 0){
            System.out.print("");
        }
        if(base>= 1 & base<=10){
            if(exp>=1 & exp<=10){
                int contador = base;
                while(base != 0){
                suma = suma+(int)(Math.pow(base,exp));
                base--;
            }
            }
         System.out.println(suma);
        }
}

}



from Recent Questions - Stack Overflow https://ift.tt/33kLZ7o
https://ift.tt/eA8V8J

No comments:

Post a Comment