HW03:Exercise Section 2.3

1)绘制程序的控制流图:

 1 public class Print {
 2     private static final int MAXPRIMES = 100;
 3     /*******************************************************
 4      * Finds and prints n prime integers
 5      * Jeff Offutt, Spring 2003
 6      ******************************************************/
 7     public static void printPrimes (int n)
 8     {
 9         int curPrime; // Value currently considered for primeness
10         int numPrimes; // Number of primes found so far.
11         boolean isPrime; // Is curPrime prime?
12         int [] primes = new int [MAXPRIMES]; // The list of prime numbers.
13
14         // Initialize 2 into the list of primes.
15         primes [0] = 2;
16         numPrimes = 1;
17         curPrime = 2;
18         while (numPrimes < n)
19         {
20             curPrime++; // next number to consider ...
21             isPrime = true;
22             for (int i = 0; i <= numPrimes-1; i++)
23             { // for each previous prime.
24                 if (isDivisable(primes[i],curPrime))
25                 { // Found a divisor, curPrime is not prime.
26                     isPrime = false;
27                     break; // out of loop through primes.
28                 }
29             }
30             if (isPrime)
31             { // save it!
32                 primes[numPrimes] = curPrime;
33                 numPrimes++;
34             }
35         } // End while
36
37         // Print all the primes out.
38         for (int i = 0; i <= numPrimes-1; i++)
39         {
40             System.out.println ("Prime: " + primes[i]);
41         }
42     } // end printPrimes
43     }

B)当n=3时输出的数组中存在2,3,5

    当n=5时输出的数组中存在2,3,5,7,11

    因此当MAXPRIMES数值为1的时候数组越界错误;

C)t=(n=1)

D)

点覆盖:{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}

边覆盖:{(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,5),(6,8),(8,9),(9,10),(10,11),(9,11),(11,2),(2,12),(12,13),(13,14),(14,15),(15,13),(13,16)}

主路径覆盖:{(1,2,3,4,5,6,7),

(1,2,3,4,5,6,8,9,10,11),

(1,2,3,4,5,6,8,9,11),

(1,2,12,13,14,15),

(1,2,12,13,16),

(1,2,3,4,5,9,10,11),

(1,2,3,4,5,9,11),

(3,4,5,6,7),

(3,4,5,6,8,9,10,11,2,12,13,14,15),

(3,4,5,6,8,9,10,11,2,12,13,16),

(3,4,5,6,8,9,11,2,12,13,14,15),

(3,4,5,6,8,9,11,2,12,13,16),

(3,4,5,9,10,11,2,12,13,14,15),

(3,4,5,9,10,11,2,12,13,16),

(3,4,5,9,11,2,12,13,14,15),

(3,4,5,9,11,2,12,13,16),

(6,7,5,9,10,11,2,12,13,14,15),

(6,7,5,9,10,11,2,12,13,16),

(6,7,5,9,11,2,12,13,14,15),

(6,7,5,9,11,2,3,4),

(6,7,5,9,10,11,2,3,4),

(6,7,5,9,11,2,3,4),

(14,15,13,16),

}

附加:基于Junit及Eclemma( jacoco)实现一个主路径覆盖的测试。

测试代码:

测试结果:

时间: 2024-11-08 19:22:13

HW03:Exercise Section 2.3的相关文章

HDU 4763:Theme Section(KMP)

http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Problem Description It's time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the progr

任务一:div section article 区别

div:毫无意义可言 article是特殊的section标签,里面内容比section分得更为详细,它比 section 具有更明确的语义, 它代表一个独立的.完整的相关内容块,一般有头有尾,可以脱离上下文独立存在,即使脱离了,意思也还是完整的:而section是作为整体的一部分存在.主要根据例子来区别他们的用法: <article> <hgroup> <h1>Apples</h1> <h2>Tasty, delicious fruit!<

&lt;&lt;C++ Primer&gt;&gt; 第四版Exercise Section 8.4.1 练习题

For exercise 8.6 1 // ConsoleApplication10.cpp : 定义控制台应用程序的入口点. 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <fstream> 7 #include <sstream> 8 9 using namespace std; 10 11 12 void print(istream &in) 13 { 14

【DeepLearning】Exercise:Learning color features with Sparse Autoencoders

Exercise:Learning color features with Sparse Autoencoders 习题链接:Exercise:Learning color features with Sparse Autoencoders sparseAutoencoderLinearCost.m function [cost,grad] = sparseAutoencoderLinearCost(theta, visibleSize, hiddenSize, ... lambda, spar

hdu4763 Theme Section

地址:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目: Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3491    Accepted Submission(s): 1623 Problem Description It's time for music!

Stanford coursera Andrew Ng 机器学习课程编程作业(Exercise 2)及总结

Exercise 1:Linear Regression---实现一个线性回归 关于如何实现一个线性回归,请参考:http://www.cnblogs.com/hapjin/p/6079012.html Exercise 2:Logistic Regression---实现一个逻辑回归 问题描述:用逻辑回归根据学生的考试成绩来判断该学生是否可以入学. 这里的训练数据(training instance)是学生的两次考试成绩,以及TA是否能够入学的决定(y=0表示成绩不合格,不予录取:y=1表示录

【DeepLearning】Exercise:PCA in 2D

Exercise:PCA in 2D 习题的链接:Exercise:PCA in 2D pca_2d.m close all %%================================================================ %% Step 0: Load data % We have provided the code to load data from pcaData.txt into x. % x is a 2 * 45 matrix, where the

[译]反-反汇编 &amp; 混淆 #1: 苹果没有遵循自己制定的Mach-O规范?

原文地址:http://reverse.put.as/2012/02/02/anti-disassembly-obfuscation-1-apple-doesnt-follow-their-own-mach-o-specifications/ 当想到这个特性时,我非常高兴!因为我喜欢突破束缚,并且写了一个CrackMe来展示这个有趣的特性. 产生问题的原因是:苹果没有遵循自己的文档与标准(Mach-O方面的),但是逆向工具却要遵循. 当逆向修改过Section信息的Mach-O文件时,IDA可能

【Ext.Net学习笔记】01:在ASP.NET WebForm中使用Ext.Net

Ext.NET是基于跨浏览器的ExtJS库和.NET Framework的一套支持ASP.NET AJAX的开源Web控件,包含有丰富的Ajax运用,其前身是Coolite. 下载地址:http://www.ext.net/download/示例地址:http://examples.ext.net/ 1.首先下载Ext.Net,地址:http://www.ext.net/download/ ,有两种框架选择,选择下载WebForms 当前版本是2.5.1,压缩包里面包含了不同版本,分别用在相应.