我正在嘗試製作一個時間表計數器。它應該輸出帶計數器的乘數,顯示答案爲零
1×5是5 2×5是10 3×5是15 高達10×5 50
的輸入是5,計數器從第i取在for循環中。
這是通過數字計算,但我無法得到它來計算結果,我看不到我失蹤。任何幫助將低於
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int input = kb.nextInt();
Math math1 = new Math(0,0);
for(int i = 0; i <= 10; i++){
math1.setNum2(i);
math1.multiplier();
System.out.println(input + " times " + i + " is " + math1.getResult());
}
} //main
} // class Program
和
public class Math {
private int num;
private int num2;
private int result;
//constructor//
public Math(int num, int num2){
this.num = num;
this.num2 = num2;
this.result = result;
}
//get//
public int getNum(){
return this.num;
}
public int getNum2(){
return this.num2;
}
public int getResult(){
return this.result;
}
//set//
public void setNum(int value){
this.num = value;
}
public void setNum2(int value){
this.num2 = value;
}
//other//
public void multiplier(){
this.num = num;
result = num * num2;
}
} // class Math
你似乎將所有東西都乘以零。再次檢查參數到數學課。 – markspace
從不使用'input'。嘗試'數學math1 =新數學(輸入,0)'。 – Arthur
'this.result = result'(在構造函數中)沒有結果參數...看起來有點簡單... – OliPro007