Я пытаюсь сделать следующее:
Если пользователь вводит число от 1 до 100, то:
- Распечатывать каждый порядковый номер от 1 до заданногочисло.
Пример ниже для входного значения 25:
1st
2nd
3rd
4th
5th
6th
7th
8th
9th
10th
11th
12th
13th
14th
15th
16th
17th
18th
19th
20th
21st
22nd
23rd
24th
25th
Я не могу понять, как добавить: st, nd, rd, th
без использования concat
.
Вот мой код:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userNum;
userNum = scnr.nextInt();
for (int i=1; i<=userNum; i++) {
System.out.println(i);
}
}
}
Есть ли другой способ сделать это?Спасибо.