[英]Random generator does not work it always shows 0
import java.util.Random;
public class PouAbilites {
protected int Health;
public int getHealth(){
return this.Health;
}
public void setHealth(final int Health){
final Random random = new Random();
final int randomInt = random.nextInt(100)+1;
this.Health=randomInt;
}
PouAbilites(){
this.Eletero=getEletero();
}
public void onscreen(){
System.out.println("Health: "+ this.Health);
}
}
The main
function is included in an other class: main
功能包含在其他类中:
package KotelezoProgram;
public class Main {
public static void main(final String[] args) {
final PouAbilites Pou = new PouAbilites();
Pou.onscreen();
}
}
call setHealth()
in between 之间调用
setHealth()
PouAbilites Pou = new PouAbilites();
Pou.onscreen();
calls 来电
Calling onscreen()
before setHealth()
will return 0
because this.Health
is just initialized in the Pou
object to zero. 在
setHealth()
onscreen()
之前调用onscreen()
会返回0
因为this.Health
刚在Pou
对象中初始化为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.