2016-08-04 11 views
0

私はタイムテーブルカウンターを作ろうとしています。それが出力になっていカウンター付き乗算器、ゼロとして回答を表示

1×5カウンタは、Iから取得され、5 2 X 5は10 3×5 15 最大5×10には入力が5で50

であるです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 
+0

すべてをゼロで乗算しているようです。再度数学クラスのパラメータを確認してください。 – markspace

+4

'input'を使用しないでください。 'Math math1 = new Math(input、0)'を試してください。 – Arthur

+1

'this.result = result'(コンストラクタ内で)結果パラメータなし...ちょっと考えました... – OliPro007

答えて

1

の下にあなたが何をしているかに関係なくゼロを掛けるように見えるいただければ幸いです。 Math math1 = new Math(0,0);は何かを意味します* 0。コード内の入力を使用する必要があります。アーサーが言及したように、Math math1 = new Math(input, 0)

1

あなたは常に0を掛けています。あなたはMathクラスでそれを使用していることを確認した後

// use the input that you took 
//let's take 5 
Math math1 = new Math(0,0); 
math1.setNum(input); 

は、mainメソッドで次のようにコードを変更し

コンストラクタを更新します。

public Math(int num, int num2){ 
    this.num = num; 
    this.num2 = num2; 
} 

resultは、ここでは何の関係もありません。

しかし、質問は、どのように入手するにはresult来る。それは次のように乗数法を変更するために

public void multiplier(){ 
    this.result = num * num2; 
} 
0

あなたは0メイトですべてを乗じています。 Mathクラスオブジェクトに渡すパラメータが表示されます。これはあなたを介して取得する必要があり

Scanner in = new Scanner(System.in); 
int number = in.nextInt(); // I suppose this is where the user enters the numbers say 5. 
Math math = new Math(number, 0); 
for(int i=1; i<=10; i++){ 
    math.setNum2(i); 
    math.multiplier(); 
    System.out.println(input + " times " + i + " is " + : math.getResult()); 
} 

は、次の行に何かを試してみてください。