首页 > 代码库 > 软件工程-第二次作业

软件工程-第二次作业

问题导读:

 

1. 环境搭建

2. 最大子数组和算法

3. 测试表格

 


 

解决方案:

操作系统

 

技术分享

 

环境搭建

1. 下载安装包

  • jdk 8

技术分享

  • eclipse neon

技术分享

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.bashrc10     fi11   else12     if [ "`id -u`" -eq 0 ]; then13       PS1=# 14     else15       PS1=$ 16     fi17   fi18 fi19 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 ]; then24   for i in /etc/profile.d/*.sh; do25     if [ -r $i ]; then26       . $i27     fi28   done29   unset i30 fi31 export JAVA_HOME=/home/jiali/jdk1.8.0_10132 export PATH=$JAVA_HOME/bin:$PATH33 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar34 ~  
  • 测试
 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 available10     -server      to select the "server" VM11                   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 property21     -verbose:[class|gc|jni]22                   enable verbose output23     -version      print product version and exit24     -version:<value>25                   Warning: this feature is deprecated and will be removed26                   in a future release.27                   require the specified version to run28     -showversion  print product version and continue29     -jre-restrict-search | -no-jre-restrict-search30                   Warning: this feature is deprecated and will be removed31                   in a future release.32                   include/exclude user private JREs in the version search33     -? -help      print this help message34     -X            print help on non-standard options35     -ea[:<packagename>...|:<classname>]36     -enableassertions[:<packagename>...|:<classname>]37                   enable assertions with specified granularity38     -da[:<packagename>...|:<classname>]39     -disableassertions[:<packagename>...|:<classname>]40                   disable assertions with specified granularity41     -esa | -enablesystemassertions42                   enable system assertions43     -dsa | -disablesystemassertions44                   disable system assertions45     -agentlib:<libname>[=<options>]46                   load native agent library <libname>, e.g. -agentlib:hprof47                   see also, -agentlib:jdwp=help and -agentlib:hprof=help48     -agentpath:<pathname>[=<options>]49                   load native agent library by full pathname50     -javaagent:<jarpath>[=<options>]51                   load Java programming language agent, see java.lang.instrument52     -splash:<imagepath>53                   show splash screen with specified image54 See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.55 jiali@peerslee-521:~$ javac56 Usage: javac <options> <source files>57 where possible options include:58   -g                         Generate all debugging info59   -g:none                    Generate no debugging info60   -g:{lines,vars,source}     Generate only some debugging info61   -nowarn                    Generate no warnings62   -verbose                   Output messages about what the compiler is doing63   -deprecation               Output source locations where deprecated APIs are used64   -classpath <path>          Specify where to find user class files and annotation processors65   -cp <path>                 Specify where to find user class files and annotation processors66   -sourcepath <path>         Specify where to find input source files67   -bootclasspath <path>      Override location of bootstrap class files68   -extdirs <dirs>            Override location of installed extensions69   -endorseddirs <dirs>       Override location of endorsed standards path70   -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 process72   -processorpath <path>      Specify where to find annotation processors73   -parameters                Generate metadata for reflection on method parameters74   -d <directory>             Specify where to place generated class files75   -s <directory>             Specify where to place generated source files76   -h <directory>             Specify where to place generated native header files77   -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files78   -encoding <encoding>       Specify character encoding used by source files79   -source <release>          Provide source compatibility with specified release80   -target <release>          Generate class files for specific VM version81   -profile <profile>         Check that API used is available in the specified profile82   -version                   Version information83   -help                      Print a synopsis of standard options84   -Akey[=value]              Options to pass to annotation processors85   -X                         Print a synopsis of nonstandard options86   -J<flag>                   Pass <flag> directly to the runtime system87   -Werror                    Terminate compilation if warnings occur88   @<filename>                Read options and filenames from file89 94 jiali@peerslee-521:~$ java -version95 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                 "+:\t" + maxSum(arr1) + "\n" +  18                 "0:\t" + maxSum(arr2) + "\n" +  19                 "-:\t" + maxSum(arr3) + "\n" +  20                 "+-:\t" + maxSum(arr4) + "\n" +  21                 "+0-:\t" + 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 }  

 

测试表格

 


用例编号

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


评价

1正数1, 1, 1, 1, 1, 166通过正常
20  0, 0, 0, 0, 0, 000通过

正常

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

正常

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

正常

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

正常

软件工程-第二次作业