今天学习了java多态·

  /**

  *利用方法重载分别求2个浮点数、3个整数和4个整数中最大的数。

*/

public class OverLoaded{

      public static int max(int a,int b,int c,int d){            //求4个整数中最大的最大数

            if(b>a){

                  a=b;

            }

            if(c>a){

                  a=c;

            }

            if(d>a){

                  a=d;

            }

            return a;

   }

public static int max (int a,int b,int c){        //求3个整数中的最大数

            if(b>a){

                  a=b;

            }

            if(c>a){

                  a=c;

            }

            return a;

   }

public static double max(double a,double b){      //求2个整数中的最大数

      f(b>a){

            a=b;

      }

      return a;

}

public static void main(String [] agrs){

      System.out.println("[45,45,0]中  \t"+max(45,45,0)+" 最大");

       System.out.println("[5,9,23,-5]中  \t"+max(5,9,23,-5)+" 最大");

      System.out.println("[10.5,10.58]中  \t"+max(10.5,10.58)+" 最大");

 

}

posted @ 2009-04-09 21:21  kanjc  阅读(135)  评论(0编辑  收藏  举报