/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import Judge.Judge;

/**
 *
 * @author user
 */
public class NewMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Judge a=new Judge();
        a.loopNumber();
    }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Judge;

import javax.swing.JOptionPane;

/**
 *
 * @author user
 */
public class Judge {

    public static void loopNumber() {
        int number=0;
        int d5 = 0, d4 = 0, d3 = 0, d2 = 0, d1 = 0;
        String str = JOptionPane.showInputDialog("输入一个1至9999之间的数");
        number = Integer.parseInt(str);
        if (number >= 1 && number <= 9999) {
            d4 = number / 1000;
            d3 = number / 100 % 10;
            d2 = number % 100 / 10;
            d1 = number % 10;
        }
        if (d4 != 0) {
            System.out.println(number + "是4位数");
            if (d4 == d1 && d3 == d2) {
                System.out.println(number + "是回文数");
            } else {
                System.out.println(number + "不是回文数");
            }
        } else if (d3 != 0) {
            System.out.println(number + "是3位数");
            if(d3==d1){
                System.out.println(number + "是回文数");
            }else{
                System.out.println(number + "不是回文数");
            }
        }else if(d2!=0){
            System.out.println(number + "是2位数");
            if(d2==d1){
                System.out.println(number + "是回文数");
            }else{
                System.out.println(number + "不是回文数");
            }
        }else if(d1!=0){
             System.out.println(number + "是2位数");
            if(d2==d1){
                System.out.println(number + "是回文数");
            }else{
                System.out.println(number + "不是回文数");
            }
        }else
            System.out.printf("\n%d不在1至99999之间",number);


    }
}

上述为第二题

下列为第三题

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import cn.GuessNumber;

/**
 *
 * @author user
 */
public class NewMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        GuessNumber g=new GuessNumber();
        g.guess();
        // TODO code application logic here
    }
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn;

import javax.swing.JOptionPane;

/**
 *
 * @author user
 */
public class GuessNumber {

    public void guess() {
        System.out.println("给你一个1至100之间的整数,请猜测这个数");
        int realNumber = (int) (Math.random() * 100) + 1;
        int yourGuess = 0;
        String str = JOptionPane.showInputDialog("输入您的猜测:");
        yourGuess = Integer.parseInt(str);
        while (yourGuess !=realNumber) {
            if (realNumber<yourGuess) {
                str = JOptionPane.showInputDialog("猜大了,再输入你的猜测:");
                yourGuess = Integer.parseInt(str);
            } else if (realNumber>yourGuess) {
                str = JOptionPane.showInputDialog("猜小了,再输入你的猜测:");
                yourGuess = Integer.parseInt(str);
            }
            
        }
        System.out.println("猜对了!");
    }
}

 posted on 2022-08-31 15:02  ZZC12312321  阅读(19)  评论(0编辑  收藏  举报  来源