一、比较大小
public class Test {
public static void main(String[] args) {
//int sore[] = {88,6,8,98};
int [] sore = new int[4];
sore[0] = 88;
sore[1] = 6;
sore[2] = 8;
sore[3] = 98;
int max;
int min;
int i;
max = min = sore[0];
for(i=1; i<4; i++){
if(max < sore[i]){
max = sore[i];
}
if(min > sore[i]){
min = sore[i];
}
}
System.out.println("max=" + max + ",min=" + min);
}
}
二、计算加减乘除
public class Test {
static int add(int a, int b){
return a+b;
}
int min(int a, int b){
return a-b;
}
int mul(int a, int b){
return a*b;
}
double div(int a,int b){
return (double)a/b;
}
public static void main(String[] args) {
Test t = new Test();
int a = 12;
int b = 5;
int add,min,mul = 1;
double div = 0.0;
add = add(a, b);//加
min = t.min(a, b);//减
mul = t.min(a, b);//乘
div = t.div(a, b);//除
System.out.println("add=" + add);
System.out.println("min=" + min);
System.out.println("mul=" + mul);
System.out.println("div=" + div);
}
}
/*
add=17
min=7
mul=7
div=2.4
*/