1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public class Min{
public static Integer min(Integer... values) throws Exception{
if(values.length == 0)
throw new Exception("aucun parametre n'a ete donne");
Integer min = values[0];
for(Integer val : values)
if(min > val) min = val;
return min;
}
public static String min(String... values) throws Exception{
if(values.length == 0)
throw new Exception("aucun parametre n'a ete donne");
String min = values[0];
for(String val : values)
if(min.compareTo(val)>0) min = val;
return min;
}
public static void main(String [] args){
try{
System.out.println(min(1,5,6));
System.out.println(min(6,564,4));
System.out.println(min("un","deux","trois"));
}catch(Exception e){
System.out.println(e.getMessage());
}
}
} |