をしようと、それは動作しますが、私は私のオブジェクト走る「カウンター」であることをすればメソッド "function()"を無限に実行すると6200に、時には最大値が〜6100または〜6300に変更されます。は「(真)しばらく」私は私がこれを試してみてください、私の方法は、ループを無限にすることはできませんなぜ私はちょうど好奇心無限ループ方式に
public class Infinity {
public static void main(String[] argv)
{
//Counter count = new Counter((short)0,(short)6180,(short)1);
//count.startCounter(true);
int a = 1;
while (true) {
a = a + 1;
System.out.println("Value: " + a);
}
}
}
これは
public class Counter
{
private short max;
private short number;
private short multiplicator;
public Counter(short n,short m,short mp)
{
System.out.println("Implementing given numbers...");
this.number=n;
this.max=m;
this.multiplicator=mp;
System.out.println("");
}
public void startCounter(boolean b)
{
if (b == true)
{
System.out.println("-----------------------------------");
System.out.println("Starting counting from " + this.number + " to " + this.max);
System.out.println("-----------------------------------");
this.function();
}
else {
System.out.println("Your Counter was set to false, abborting Start...");
}
}
public void function()
{
if (this.number < this.max)
{
this.number = (short)(this.number + this.multiplicator);
System.out.println("Number: " + this.number);
this.function();
}
else {
System.out.println("Ending of Number");
}
}
}
私のメインクラスですこれは私の追加のカウンタークラスです
'StackOverflow'エラーが発生しましたか? –
@ ElSadoffあなたはStackoverflowを意味しますか? – Li357
私は例えば9000に私の最大数を設定すると、 "Counter.function(Counter.java:36)で"多くの行を取得する – zapole