1、源代码:

import java.util.Scanner;
 public class Main {
 
   public static void main(String[] args) {
        System.out.println("输入比较的数的个数");
        Scanner in = new Scanner(System.in);
          int length;
              length = in.nextInt();
                  while( length<=0)
                  {
                      System.out.println("输入错误  重新输入");
                      length = in.nextInt();
                      }
            Max max = new Max(length);
            max.Input();
            max.Largest(max.Array, max.length);
            max.Output();
   }    
 
 }

 class Max
 {
     int Array[];
     int length;
     int max;
     int i;
     public Max(int l)
    {
         length = l;
        }//构造方法
   int Largest(int list[],int length)
   {
       max = list[0];
     for( i=0;i<length;i++)
         {
           if(list[i]>max)
            {
                max = list[i];
           }
        }
       return max;
    }    
    void Input()
   {     
        Array = new int [length];
         Scanner in = new Scanner(System.in);

         for( i=0;i<length;i++)
              {            
             Array[i]=in.nextInt();
              }
    }
     void Output()
             {
             System.out.println(max);
             }

     }

 

2.运行截图:

 

posted on 2016-03-21 17:52  憧憧  阅读(147)  评论(0编辑  收藏  举报