Created
November 11, 2012 22:10
-
-
Save marioplumbarius/4056449 to your computer and use it in GitHub Desktop.
Programa em Java de cálculo de potência.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Faça um programa de cálculo de potência que solicite dois números (n e m) | |
* e faça o cálculo de n^m. Repita esse cálculo até o usuário digitar n = 0. | |
*/ | |
package cap14; | |
import java.util.Scanner; | |
public class Exercicio04 { | |
public static void main(String[] args){ | |
Scanner ent = new Scanner(System.in); | |
int base, pot; | |
int res = 1; | |
do{ | |
System.out.println("Digite a base"); | |
base = ent.nextInt(); | |
if(base != 0){ | |
System.out.println("Digite a potencia"); | |
pot = ent.nextInt(); | |
do{ | |
res = res * base; | |
pot--; | |
}while(pot > 0); | |
System.out.println(res); | |
res = 1; | |
} | |
}while((base != 0)); | |
System.out.println("Você digitou base = 0. O programa foi finalizado."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment