向用户询问起始值。将输出设置为每行显示 10 个值,然后另起一行

Ask the user for the starting value. Set up the output to display 10 values per line and then start a new line

public class StayPositive {

  public static void main(String[] args) {
    System.out.println("Counting down..");
    int i = 59;
    while (i >= 0) {
      System.out.println(i);
      i--;
    }
  }
}

您可以使用 Scanner 获取用户输入。并使用 % 函数在每 10 个数字后更改衬里:

public static void main(String[] args) {
    Scanner scanner =  new Scanner(System.in);
    System.out.print("Give a number: ");
    int givenNumber = Integer.valueOf(scanner.nextLine());

    for(int i = givenNumber, j=1 ; i>=0 ; i--, j++) {
      if(j%10 == 0) {
        System.out.println(i);
      } else {
        System.out.print(i);;
      }
    }
  }

输入:59

输出:

59585756555453525150
49484746454443424140
39383736353433323130
29282726252423222120
19181716151413121110
9876543210