码迷,mamicode.com
首页 > 其他好文 > 详细

课堂测试 二

时间:2016-03-21 19:52:52      阅读:135      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!