lundi 21 décembre 2015

Incompatible types without reason [duplicate]

This question already has an answer here:

So I'm trying to make a class that gives a random power of two and for some reason i get this error while compiling: "RandomGeneratorExtended.java:124: error: incompatible types: possible lossy conversion from double to int int finPo=Math.pow(2, power);" What can be wrong? I haven't used any double as the error says! (I'm using the acm.utils package which contains RandomGenerator.class)

   public int nextPoTwo(int n){
        int po=0;
        int num=1;
        while (num < n){
            num=num*2;
            po += 1;
        }
        if (num!=n){
            num=num/2;
            po = po-1;
        int power = rgen.nextInt(0,po);
        int finPo=Math.pow(2, power);
        return finPo;
        }




Aucun commentaire:

Enregistrer un commentaire