案例一:从键盘输入两个数据,比较大小
import java.util.Scanner;
class FunctionTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("input a number:");
int a = sc.nextInt();
System.out.println("input another nuber:");
int b = sc.nextInt();
int result = Getmax(a,b);
System.out.println("maxvalue:"+result);
}
public static int Getmax(int a,int b) {
if(a > b) {
return a;
}else {
return b;
}
}
}
执行结果:
D:\>java FunctionTest
input a number:
45
input another nuber:
88
maxvalue:88
案例二:比较键盘输入的两个数值是否相等
输出结果:
D:\java_code>java FunctionTest01
input a number:
88
input another nuber:
88
True or False: true
#####################################################
输出结果:
D:\java_code>java FunctionTest02
input a number:
8
input another nuber:
8
********
********
********
********
********
********
********
********