Write
a method which takes 3 integers as parameters and adds the 2 highest numbers
out of 3 then and returns the result. e.g. m1(5,7,2) will return you 12 (5+7).
class Utility{
static int addMax2(int i, int j, int k){
int max1, max2;
if(i<=j && i<=k){
return k+j;
}
else if(j<=k && j<=i){
return k+i;
}
else if(k<=j && k<=i){
return i+j;
}
else if(i==j && i==k){
return i+j;
}
return 0;
}
}
class Demo{
public static void main(String[] args){
int i = Integer.parseInt(args[0]);
int j = Integer.parseInt(args[1]);
int k = Integer.parseInt(args[2]);
int ans = Utility.addMax2(i,j,k);
System.out.println(ans);
}
}
No comments:
Post a Comment