/*
方法练习1:比较两个数字
题目:定义一个方法,用来判断两个数字是否相同。
*/
package com.xiaxia;
public class MethodExercise1 {// Method exercise:方法练习
public static void main(String[] args) {
System.out.println(test1(10, 10) + "\n" + test2(10, 10) + "\n"
+ test3(10, 10) + "\n" + test4(10, 10));// true
System.out.println(test1(20, 10) + "\n" + test2(20, 10) + "\n"
+ test3(20, 10) + "\n" + test4(20, 10));// false
}
// 方法1
public static boolean test1(int a, int b) {
boolean c;
if (a == b) {
c = true;
} else {
c = false;
}
return c;
}
// 方法2
public static boolean test2(int a, int b) {
boolean c = a == b ? true : false;
return c;
}
// 方法3
public static boolean test3(int a, int b) {
boolean c = a == b;
return c;
}
public static boolean test4(int a, int b) {
return a == b;
}
}