Java实验上机实践三实验1代码

    科技2024-11-01  16

    package com.company; import java.util.Scanner; public class Main { public static void main(String[] args) { while (true) { int number = 0, d5, d4, d3, d2, d1; Scanner reader = new Scanner(System.in); System.out.println("请输入一个1至99999之间的数字:(输入-1结束)"); number = reader.nextInt(); if (number == -1) { break; } if (number >= 1 && number <= 99999) { d5 = number / 10000; d4 = number % 10000 / 1000; d3 = number % 1000 / 100; d2 = number % 100 / 10; d1 = number % 10; if (d5 != 0) { System.out.println(number + "是五位数"); if ((d1 == d5) && (d2 == d4)) { System.out.println(number + "是回文数"); } else { System.out.println(number + "不是回文数"); } } else if ((d5 == 0) && (d4 != 0)) { System.out.println(number + "是四位数"); if ((d1 == d4) && (d2 == d3)) { System.out.println(number + "是回文数"); } else { System.out.println(number + "不是回文数"); } } else if ((d5 == 0) && (d4 == 0) && (d3 != 0)) { System.out.println(number + "是三位数"); if (d1 == d3) { System.out.println(number + "是回文数"); } else { System.out.println(number + "不是回文数"); } } else if ((d5 == 0) && (d4 == 0) && (d3 == 0) && (d2 != 0)) { System.out.println(number + "是两位数"); if (d1 == d2) { System.out.println(number + "是回文数"); } else { System.out.println(number + "不是回文数"); } } else if ((d5 == 0) && (d4 == 0) && (d3 == 0) && (d2 == 0) && (d1 != 0)) { System.out.println(number + "是一位数"); System.out.println(number + "是回文数"); } } else { System.out.println(number + "不在1~99999的范围内"); } } } }

     

    Processed: 0.033, SQL: 8