zoukankan      html  css  js  c++  java
  • 软件工程-课上单元测试

    单元测试:

    源代码:

     1 import java.util.Scanner;
     2 public class List {
     3 
     4     public static void main(String[] args) {
     5         // TODO Auto-generated method stub
     6         System.out.println("输入长度");
     7         Scanner t = new Scanner(System.in);
     8         int l;
     9         l = t.nextInt();
    10         while(l<=0)
    11         {
    12             System.out.println("长度未大于0  请重新输入");
    13             l = t.nextInt();
    14         }
    15         
    16         Max m = new Max(l);
    17         m.Input();
    18         m.Largest(m.list, m.length);
    19         m.Output();
    20     }
    21 
    22 }
    23 
    24 class Max
    25 {
    26     int list[];
    27     int length;
    28     int max;
    29     int i;
    30     public Max(int s)
    31     {
    32         length = s;
    33     }
    34     int Largest(int list[],int length)
    35     {
    36         max = list[0];
    37         for( i=0;i<length;i++)
    38         {
    39             if(list[i]>max)
    40             {
    41                 max = list[i];
    42             }
    43         }
    44         return max;
    45     }
    46     void Input()
    47     {
    48         Scanner k = new Scanner(System.in);
    49         list = new int [length];
    50         System.out.println("请输入数组");
    51         for( i=0;i<length;i++)
    52         {            
    53             list[i]=k.nextInt();
    54         }
    55     }
    56     void Output()
    57     {
    58         System.out.println(max);
    59     }
    60     
    61 
    62 }

    测试截图:

    1、当数组长度为负数时:

    2、当数组长度为0时

    3、当输入值都为正数时:

    4、当输入数都为负数时:

    5、当输入数正数负数都有时:

    6、当输入有相同数时:

  • 相关阅读:
    从O(n^3) 到 O(n)求最大连续和
    冲刺博客NO.6
    冲刺博客NO.5
    冲刺博客NO.4
    冲刺博客NO.3
    冲刺博客NO.2
    冲刺博客NO.1
    结对开发:四则运算(网页版)
    课堂作业3
    软件工程概论02~ 四则运算
  • 原文地址:https://www.cnblogs.com/hzxsg0919/p/5301432.html
Copyright © 2011-2022 走看看