- 通过对小时部分的值来进行后缀(PM或者AM)的判断,三种情况
import java.util.Scanner;
public class Main {
public static void main (String [] args) {
Scanner sc = new Scanner(System.in);
String start = sc.nextLine();
String [] starts = start.split(":");
int hour = Integer.parseInt(starts[0]);
if (hour >= 0 && hour < 12) {
System.out.println(hour + ":" + starts[1]+ " AM");
}
else if (hour == 12) {
System.out.println(hour + ":" + starts[1]+ " PM");
} else {
hour -= 12;
System.out.println(hour + ":" + starts[1]+ " PM");
}
}
}