I want to get a 3 digit number from the user's input using scanner input first. The 3 digits number can be 001 or 999 but not 000. Then I need to print this number in a sentence "***th person". Let's say if the 3 digit number is 021 then I expect it will print "21st person".
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a value ");
int abc = input.nextInt();
String suffix = "";
if(abc==000){
System.out.println("invalid input");
}
switch(abc%10){ //get the last digit of the value
case 1: suffix = "st";break;
case 2: suffix = "nd";break;
case 3: suffix = "rd";break;
default: suffix = "th";
}
System.out.println(abc+suffix);
}
}
How can I change my code such that the program will check 11th 12th 13th 111th cases?