
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
MyInteger integer1=new MyInteger(11);
System.out.println(integer1.isOdd());
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
MyInteger integer2=new MyInteger();
System.out.print(integer2.isEven(num));
}
}
//MyInteger类
public class MyInteger {
int value;
//构造方法
public MyInteger(int value){
this.value=value;
}
public MyInteger(){
}
public boolean isEven(){
if(value%2==0)
return true;
else
return false;
}
public boolean isOdd(){
if(value%2==0)
return false;
else
return true;
}
public boolean isPrime(){
for(int x=2;x<value-1;x++){
if(value%x==0)
return false;
}
return true;
}
public boolean isEven(int num){
if(num%2==0)
return true;
else
return false;
}
public boolean isOdd(int num){
if(num%2==0)
return false;
else
return true;
}
public boolean isPrime(int num){
for(int x=2;x<num-1;x++){
if(num%x==0)
return false;
}
return true;
}
}
MyInteger类实现
本文介绍了一个名为MyInteger的Java类的实现。该类提供了一系列方法用于判断整数值是否为偶数、奇数或素数。此外,还展示了如何实例化此类并调用其方法。
9047

被折叠的 条评论
为什么被折叠?



