(1):判断回文数:
package UI;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一个数字:");
int num = scanner.nextInt();
if(isPalindrome(num)){
System.out.println("是回文数!");
}else{
System.out.println("不是回文数!");
}
public static boolean isPalindrome(int num){
return reverse(num) == num;
}
//反序,如果反转这个数字跟原来的数字是一样的说明是回文数
public static int reverse(int num){
int sum = 0;
while(true){
sum = sum * 10 + num % 10;
num /= 10;
if(num == 0){
return sum;
}
}
}
}
}
(2):通过文件路径,获取文件名:
package UI;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入路径:");
String input = scanner.next();
System.out.pri