I am trying to do the following:
If a number between 1 and 100 is entered by the user, then:
- Print out each ordinal from 1 to the given number.
Example below is for the input value of 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
I can't figure out how to add the: st, nd, rd, th
without using concat
.
Here is my code:
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);
}
}
}
Is there another way to do this? Thanks.