首页 > 其他 > 详细

课堂测试 二

时间:2016-03-21 19:51:06      阅读:234      评论:0      收藏:0      [点我收藏+]

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.运行截图:技术分享技术分享技术分享技术分享

 

课堂测试 二

原文:http://www.cnblogs.com/3066405538a/p/5302929.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!