请问如何按以下要求编写一段Java method用来比较两个整数大小
发布网友
发布时间:2024-05-02 08:53
我来回答
共3个回答
热心网友
时间:2024-09-30 04:19
public static void main(String[] args) {
Integer value =1;
Integer value2 = 10;
if(value.intValue()>value2.intValue()){
System.out.println("value大于value2");
}else{
System.out.println("value小于等于value2");
}
}
热心网友
时间:2024-09-30 04:19
public class Test {
public String compareValues (int x, int y){
int result = x - y;
if(result > 0){
return x+" is larger than "+y;
}else if(result == 0){
return "the two values are equal";
}else{
return y+" is larger than "+x;
}
}
public static void main(String[] args) {
System.out.println(new Test().compareValues(4,2));
}
}
热心网友
时间:2024-09-30 04:19
public static void main(String[] args) throws IOException {
System.out.println(compareValues(3,4));
}
private static String compareValues(int x, int y){
String ret;
if(x > y){
ret = x + " is larger than " + y;
}else if(x < y){
ret = y + " is larger than " + x;
}else{
ret = "the two values are equal";
}
return ret;
}