나는 "while (true)"로 이것을 시도 할 때 무한히 반복 할 수 없다는 것이 궁금합니다. 그렇다면 작동하는 "Counter"라는 객체를 사용하면됩니다. 메서드 "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");
}
}
}
이것은 Dinamically 묶는 범위 내 추가 카운터 클래스
'StackOverflow' 오류가 발생합니까? –
@ 엘리사 도프 당신 Stackoverflow 의미합니까? – Li357
최대 숫자를 9000으로 설정하면 "Counter.function (Counter.java:36)"에 "012"가 표시됩니다. – zapole