zoukankan      html  css  js  c++  java
  • 软件工程-第二次作业

    问题导读:

    1. 环境搭建

    2. 最大子数组和算法

    3. 测试表格


    解决方案:

    操作系统

    环境搭建

    1. 下载安装包

    2. 安装配置JDK

    • 解压
    1 tar -xvzf jdk-8u101-linux-x64.tar.gz
    • 配置
    1 sudo vi /etc/profile
    • profile
     1 # /etc/profile: system-wide .profile file for the Bourne shell (sh(2))
     2 # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
     3 
     4 if [ "$PS1" ]; then
     5   if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
     6     # The file bash.bashrc already sets the default PS1.
     7     # PS1='h:w$ '
     8     if [ -f /etc/bash.bashrc ]; then
     9       . /etc/bash.bashrc
    10     fi
    11   else
    12     if [ "`id -u`" -eq 0 ]; then
    13       PS1='# '
    14     else
    15       PS1='$ '
    16     fi
    17   fi
    18 fi
    19 
    20 # The default umask is now handled by pam_umask.
    21 # See pam_umask(8) and /etc/login.defs.
    22 
    23 if [ -d /etc/profile.d ]; then
    24   for i in /etc/profile.d/*.sh; do
    25     if [ -r $i ]; then
    26       . $i
    27     fi
    28   done
    29   unset i
    30 fi
    31 export JAVA_HOME=/home/jiali/jdk1.8.0_101
    32 export PATH=$JAVA_HOME/bin:$PATH
    33 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    34 ~  
    • 测试
     1 jiali@peerslee-521:~$ source /etc/profile
     2 jiali@peerslee-521:~$ java
     3 Usage: java [-options] class [args...]
     4            (to execute a class)
     5    or  java [-options] -jar jarfile [args...]
     6            (to execute a jar file)
     7 where options include:
     8     -d32      use a 32-bit data model if available
     9     -d64      use a 64-bit data model if available
    10     -server      to select the "server" VM
    11                   The default VM is server,
    12                   because you are running on a server-class machine.
    13 
    14 
    15     -cp <class search path of directories and zip/jar files>
    16     -classpath <class search path of directories and zip/jar files>
    17                   A : separated list of directories, JAR archives,
    18                   and ZIP archives to search for class files.
    19     -D<name>=<value>
    20                   set a system property
    21     -verbose:[class|gc|jni]
    22                   enable verbose output
    23     -version      print product version and exit
    24     -version:<value>
    25                   Warning: this feature is deprecated and will be removed
    26                   in a future release.
    27                   require the specified version to run
    28     -showversion  print product version and continue
    29     -jre-restrict-search | -no-jre-restrict-search
    30                   Warning: this feature is deprecated and will be removed
    31                   in a future release.
    32                   include/exclude user private JREs in the version search
    33     -? -help      print this help message
    34     -X            print help on non-standard options
    35     -ea[:<packagename>...|:<classname>]
    36     -enableassertions[:<packagename>...|:<classname>]
    37                   enable assertions with specified granularity
    38     -da[:<packagename>...|:<classname>]
    39     -disableassertions[:<packagename>...|:<classname>]
    40                   disable assertions with specified granularity
    41     -esa | -enablesystemassertions
    42                   enable system assertions
    43     -dsa | -disablesystemassertions
    44                   disable system assertions
    45     -agentlib:<libname>[=<options>]
    46                   load native agent library <libname>, e.g. -agentlib:hprof
    47                   see also, -agentlib:jdwp=help and -agentlib:hprof=help
    48     -agentpath:<pathname>[=<options>]
    49                   load native agent library by full pathname
    50     -javaagent:<jarpath>[=<options>]
    51                   load Java programming language agent, see java.lang.instrument
    52     -splash:<imagepath>
    53                   show splash screen with specified image
    54 See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
    55 jiali@peerslee-521:~$ javac
    56 Usage: javac <options> <source files>
    57 where possible options include:
    58   -g                         Generate all debugging info
    59   -g:none                    Generate no debugging info
    60   -g:{lines,vars,source}     Generate only some debugging info
    61   -nowarn                    Generate no warnings
    62   -verbose                   Output messages about what the compiler is doing
    63   -deprecation               Output source locations where deprecated APIs are used
    64   -classpath <path>          Specify where to find user class files and annotation processors
    65   -cp <path>                 Specify where to find user class files and annotation processors
    66   -sourcepath <path>         Specify where to find input source files
    67   -bootclasspath <path>      Override location of bootstrap class files
    68   -extdirs <dirs>            Override location of installed extensions
    69   -endorseddirs <dirs>       Override location of endorsed standards path
    70   -proc:{none,only}          Control whether annotation processing and/or compilation is done.
    71   -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
    72   -processorpath <path>      Specify where to find annotation processors
    73   -parameters                Generate metadata for reflection on method parameters
    74   -d <directory>             Specify where to place generated class files
    75   -s <directory>             Specify where to place generated source files
    76   -h <directory>             Specify where to place generated native header files
    77   -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
    78   -encoding <encoding>       Specify character encoding used by source files
    79   -source <release>          Provide source compatibility with specified release
    80   -target <release>          Generate class files for specific VM version
    81   -profile <profile>         Check that API used is available in the specified profile
    82   -version                   Version information
    83   -help                      Print a synopsis of standard options
    84   -Akey[=value]              Options to pass to annotation processors
    85   -X                         Print a synopsis of nonstandard options
    86   -J<flag>                   Pass <flag> directly to the runtime system
    87   -Werror                    Terminate compilation if warnings occur
    88   @<filename>                Read options and filenames from file
    89 94 jiali@peerslee-521:~$ java -version
    95 java version "1.8.0_101"
    96 Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
    97 Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

    3. 安装eclipse neon

    1 tar -xvf eclipse-jee-neon-1-linux-gtk-x86_64.tar.gz 

     

    最大子数组和算法实现

     1 package p01;
     2 public class MaxSubArraySum {  
     3     public static void main(String []args) {  
     4         /* 
     5          * 测试数组 
     6          */  
     7         int []arr1 = {1, 1, 1, 1, 1, 1};  
     8         int []arr2 = {0, 0, 0, 0, 0, 0};  
     9         int []arr3 = {-9, -2, -3, -5, -3};  
    10         int []arr4 = {1, -2, 3, 5, -3, 2};  
    11         int []arr5 = {0, -2, 3, 5, -1, 2};  
    12           
    13         /* 
    14          * 测试结果 
    15          */  
    16         System.out.println(  
    17                 "+:	" + maxSum(arr1) + "
    " +  
    18                 "0:	" + maxSum(arr2) + "
    " +  
    19                 "-:	" + maxSum(arr3) + "
    " +  
    20                 "+-:	" + maxSum(arr4) + "
    " +  
    21                 "+0-:	" + maxSum(arr5)    
    22                 );  
    23           
    24     }  
    25       
    26     static int maxSum(int []arr) {  
    27         int nStart = arr[0];  
    28         int nAll = arr[0];  
    29           
    30         /* 
    31          * 动态规划: 
    32          * max{arr[i],arr[i]+start[i+1],all[i]} 
    33          * 注: 
    34          * arr[i] -> 第 i 个数值 
    35          * arr[i] + start[i+1] -> 第 i 个 数值 加上 下一个数值 
    36          * all[i] -> 当前最大子数组和 
    37          */  
    38         for(int i = 1; i < arr.length; i++) {  
    39             nStart = Math.max(arr[i], arr[i]+nStart);  
    40             nAll = Math.max(nStart, nAll);  
    41         }  
    42         return nAll;  
    43     }  
    44 }  

    代码托管:coding.net

    测试表格


    用例编号

    用例描述 输入数据 预期输出数据 实际输出数据 通过/不通过


    评价

    1 正数 1, 1, 1, 1, 1, 1 6 6 通过 正常
    2 0   0, 0, 0, 0, 0, 0 0 0 通过

    正常

    3 负数 -9, -2, -3, -5, -3 -2 -2 通过

    正常

    4 正数 和 负数  1, -2, 3, 5, -3, 2 8 8 通过

    正常

    5 正数、0 和 负数 0, -2, 3, 5, -1, 2 9 9 通过

    正常

  • 相关阅读:
    Sip协议中的严格路由和松路由
    读书有感(转)
    c# ini文件操作类(简单配置文件)
    android ApiDemos学习1 主界面动态ListView显示
    android 长度单位
    ArcGIS Engine 常用方法
    android simcard
    android 屏蔽home键操作
    android activity
    android ListView
  • 原文地址:https://www.cnblogs.com/lipenglin/p/5931942.html
Copyright © 2011-2022 走看看