Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- public class Exercice4 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.print(puissance());
- }
- public static long puissance() {
- int [] ab = lireEntier();
- double a = ab[0];
- double b = ab[1];
- double p = Math.pow(a,b);
- long puissance = (long)p;
- long al = (long)a;
- long bl = (long)b;
- System.out.println(al + "^" + b + "=");
- return puissance;
- }
- public static int[] lireEntier() {
- int a = 0;
- int b = 0;
- boolean isPositiveInt;
- do {
- try {
- Scanner inputUser = new Scanner(System.in);
- System.out.print("Rentrer un nombre entier positif pour a : ");
- a = inputUser.nextInt();
- System.out.print("Rentrer un nombre entier positif pour b : ");
- b = inputUser.nextInt();
- isPositiveInt = true;
- if (a < 0 || b < 0) {
- System.out.print("Les entiers doivent être positifs !\n");
- isPositiveInt = false;
- }
- } catch (Exception e) {
- System.out.println("La valeur saisie n'est pas un entier");
- isPositiveInt = false;
- }
- } while (isPositiveInt != true);
- return new int[] { a, b };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement