Advertisement
cesarnascimento

elevação de potencia sem math.pow usando for

May 30th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. package exercicios;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ex13 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         int base,pot;
  10.        
  11.         System.out.println("Digite o numero da base: ");
  12.         base = sc.nextInt();
  13.        
  14.         System.out.println("Digite a potencia: ");
  15.         pot = sc.nextInt();
  16.         int resultado = base;
  17.         for(int i = 1; i<pot; i++){
  18.             resultado *= base;
  19.            
  20.         }
  21.         System.out.println(resultado);
  22.        
  23.        
  24.     }
  25.  
  26. }
  27. //faça um programa que peça dois numeros, base e expoente,
  28. //calcule e mostre o primeiro elevado ao segundo.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement