Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3.  
  4. public class Exercice4 {
  5.  
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.         System.out.print(puissance());
  9.     }
  10.    
  11.     public static long puissance() {
  12.         int [] ab = lireEntier();
  13.        
  14.         double a = ab[0];
  15.         double b = ab[1];
  16.        
  17.         double p = Math.pow(a,b);
  18.        
  19.         long puissance = (long)p;
  20.        
  21.         long al = (long)a;
  22.         long bl = (long)b;
  23.        
  24.         System.out.println(al + "^" + b + "=");
  25.    
  26.     return puissance;
  27.     }
  28.    
  29.    
  30.    
  31.  
  32.     public static int[] lireEntier() {
  33.         int a = 0;
  34.         int b = 0;
  35.  
  36.         boolean isPositiveInt;
  37.  
  38.         do {
  39.             try {
  40.                 Scanner inputUser = new Scanner(System.in);
  41.  
  42.                 System.out.print("Rentrer un nombre entier positif pour a : ");
  43.                 a = inputUser.nextInt();
  44.  
  45.                 System.out.print("Rentrer un nombre entier positif pour b : ");
  46.                 b = inputUser.nextInt();
  47.  
  48.                 isPositiveInt = true;
  49.  
  50.                 if (a < 0 || b < 0) {
  51.                     System.out.print("Les entiers doivent être positifs !\n");
  52.                     isPositiveInt = false;
  53.                 }
  54.  
  55.             } catch (Exception e) {
  56.                 System.out.println("La valeur saisie n'est pas un entier");
  57.                 isPositiveInt = false;
  58.             }
  59.  
  60.         } while (isPositiveInt != true);
  61.  
  62.         return new int[] { a, b };
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement