0
我希望用戶輸入一個數字,並讓程序輸出所有數字到該數字。而不是按順序打印數字(1,2,3等),它會打印用戶號碼並向其中添加一個號碼。for循環計數到用戶號碼
import java.util.*;
public class Count
{
public static final Scanner CONSOLE = new Scanner(System.in);
public static void main(String [] args)
{
int lastNumber = 0;
System.out.println("Enter number to count up to: ");
lastNumber = CONSOLE.nextInt();
int k = 1;
for(; k<=lastNumber; k++);
{
System.out.print(k);
}
}
}
...其實只有一個額外的分號,但謝謝 – viv 2014-09-25 03:23:23