方法 判断是否是偶数 奇数

//公共类
public class getRes{

    //定义一个main方法
    public static void main(String[] args){
        //创建对像
        AA a=new AA();
        //调用方法
        Scanner myScanner = new Scanner(System.in);
        //请输入数字
        System.out.println("please input num :");
        int num=myScanner.nextInt();
        boolean res=a.getRes(num);//必须在主方法里调用此方法
        System.out.println(res+" ");
    }
}
//自定义类        
class AA{
    public boolean getRes(int num){
        if(num%2==0){
            System.out.print("偶数");
            boolean res=true;
            return res;
        }else{
            boolean res=false;
            System.out.print("奇数");
            return res;

        }
        
        
    }
}

 

posted @ 2025-05-06 13:35  胖豆芽  阅读(59)  评论(0)    收藏  举报