我是新來的Java編程人員,我正在嘗試學習繩索。我遇到了一個問題,這個問題源於我無法檢查一個變量是否是一個整數。如何檢查一個變量是否爲整數
int[] values = new int[3];
private Random rand = new Random();
num1 = rand.nextInt(70);
num2 = rand.nextInt(70);
num3 = rand.nextInt(70);
values[1] = num1 + num2
//we are dividing values[1] by num3 in order to produce an integer solution. For example (4 + 3)/2 will render an integer answer, but (4 + 3)/15 will not.
//The (correct) answer is values[2]
values[2] = values[1]/num3
if (num3 > values[1]) {
//This is done to ensure that we are able to divide by the number to get a solution (although this would break if values[1] was 1).
num3 = 2
while (values[2] does not contain an integer value) {
increase num3 by 1
work out new value of values[2]
}
} else {
while (values[2] does not contain an integer value) {
increase num3 by 1
work out new value of values[2] <--- I'm not sure if this step is necessary
}
}
System.out.println(values[2]);
如果(NUM ==(INT)NUM) { // Number是整數 } –
何處以及如何'values'定義? –
可能的重複[如何檢查一個值的類型是Integer?](http:// stackoverflow。com/questions/12558206/how-can-i-check-if-a-value-is-of-type-integer) –