Java小试牛刀
程序员文章站
2024-03-09 11:08:29
...
package yys;
import java.util.Scanner;
public class demo03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please input a and b :");
int a = sc.nextInt();
int b = sc.nextInt();
isBiggerEvenOrOdd(a, b);
}
public static void isBiggerEvenOrOdd(int a, int b){
// 求取较大数
int max = a > b ? a : b;
System.out.println("较大数是:" + max);
//判断a是否是偶数
if(a % 2 == 0){
System.out.println("a是偶数");
}
else {
System.out.println("a是奇数");
}
//判断b是否是偶数
if(b % 2 == 0){
System.out.println("b是偶数");
}
else {
System.out.println("b是奇数");
}
}
}