任务描述:
输入一个三位整数,将其个位和百位交换后输出
任务要求:
package march0317_0331;
import java.util.Scanner;
public class m240323 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入一个三位整数 :");
String input = scanner.nextLine();
int number = Integer.parseInt(input);
if (number < 100 || number > 999) {
System.out.println("输入错误,请确保输入的是一个三位整数!");
return;
}
int hundredth = number / 100;
int tenth = (number % 100) / 10;
int unit = number % 10;
int swappedNumber = unit * 100 + tenth * 10 + hundredth;
System.out.println("交换个位和百位后:" + swappedNumber);
}
}