第三次作业
2016-03-31 00:15
393 查看
public class Prime { /******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public void printPrimes (int n) { int curPrime; // Value currently considered for primeness int numPrimes; // Number of primes found so far. boolean isPrime; // Is curPrime prime? int [] primes = new int [100]; // The list of prime numbers. // Initialize 2 into the list of primes. primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; // next number to consider ... isPrime = true; for (int i = 0; i <= numPrimes-1; i++) { // for each previous prime. if (curPrime%primes[i] == 0) { // Found a divisor, curPrime is not prime. isPrime = false; break; // out of loop through primes. } } if (isPrime) { // save it! primes[numPrimes] = curPrime; numPrimes++; } } // End while // Print all the primes out. for (int i = 0; i <= numPrimes-1; i++) { System.out.println ("Prime: " + primes[i]); } } // end printPrimes }
import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.junit.*; public class PrimeTest { Prime p; PrintStream console = null; // 声明(为null):输出流 (字符设备) console ByteArrayOutputStream bytes = null; // 声明(为null):bytes 用于缓存console 重定向过来的字符流 @Before public void setup() { p = new Prime(); bytes = new ByteArrayOutputStream(); // 分配空间 console = System.out; // 获取System.out 输出流的句柄 System.setOut(new PrintStream(bytes)); // 将原本输出到控制台Console的字符流 重定向 到 bytes } @After public void tearDown() { System.setOut(console); } @Test public void test() { p.printPrimes(3); String s = new String("Prime: 2\r\nPrime: 3\r\nPrime: 5\r\n"); // 注意:控制台的换行,这里用 '\n' 表示 assertEquals("11111111",s, bytes.toString()); // bytes.toString() 作用是将 bytes内容 转换为字符流 } }
当MAXPRIMES等于3或4时。t2=(n=5)会越界。但t1=(n=3)不越界
n=1
节点覆盖{1,2,3,4,5,6,7,8,9,10,11,12}
{(1,2),(2,3),(3,4),(4,5),(5,6),(6,4),(4,5),(5,7),(7,8),(8,2),(2,9),(9,10),(10, 11),(11,9),(9,12)}
{(1,2),(2,3),(3,4),(4,5),(5,6),(6,4),(4,7),(7,8),(8,2),(2,9),(9,10),(10, 11),(11,9),(9,12)}
基本路径覆盖:={(1,2,10,11),(3,4,8,9,2,10,11,12),(3,4,8,2,10,11,12),(3,4,8,9,2,10,11),(3,4,8,2,10,11),(4,5,7,4),(4,5,6,8,9,2,3,4),(4,5,6,8,2,3,4),(4,8,9,2,3,4),(4,8,2,3,4),(5,7,4,5),(5,6,8,9,2,3,4,5),(1,2,3,4,8,9),(1,2,3,4,5,7),(1,2,3,4,5,6,8,9),(1,2,10,11,12),(2,3,4,8,9,2),(2,3,4,8,2),(2,3,4,5,7),(2,3,4,5,6,8,9,2),(2,3,4,5,6,8,2),(2,10,11,12),(2,10,11),(3,4,5,6,8,9,2,3),(3,4,5,6,8,2,3),(3,4,8,9,2,3),(3,4,8,2,3),(3,4,5,6,8,9,2,10,11,12),(3,4,5,6,8,2,10,11,12),(3,4,5,6,8,9,2,10,11),(3,4,5,6,8,2,10,11),(5,6,8,2,3,4,5),(6,8,9,2,3,4,5,6),(6,8,9,2,3,4,5,6),(6,8,9,2,3,4,5,7),(6,8,2,3,4,5,7),(7,4,5,7),(7,4,8,9,2,3),(7,4,8,2,3),(7,4,5,6,8,9,2,3),(7,4,5,6,8,2,3),(7,4,5,6,8,9,2,10,11,12),(7,4,5,6,8,9,2,10,11),(7,4,5,6,8,2,10,11,12),(7,4,5,6,8,2,10,11),(7,4,8,9,2,10,11,12),(7,4,8,9,2,10,11),(7,4,8,2,10,11,12),(7,4,8,2,10,11),(8,2,3,4,8),(8,9,2,3,4,8),(8,2,3,4,5,6,8),(8,9,2,3,4,5,6,8),(9,2,3,4,8,9),(9,2,3,4,5,6,8,12)}.
相关文章推荐
- 常用正则表达式
- ios获取文本长度
- C++写实拷贝
- AsyncTask与Thread的区别
- 15个数字排序 vb
- Http的持久连接(Keep-Alive模式)
- 什么是IO(六)- Driver & IO Channel
- Block的基本使用
- lesson 5 保存数据 上
- 模板实现双向链表
- 什么是IO(五)- 逻辑卷管理
- Unity3d Gis 坐标转换
- 14. 税收规则(Tax Rules)
- 【4】JAVA---地址App小软件(UpdatePanel.class)(表现层)
- 【4】JAVA---地址App小软件(UpdatePanel.class)(表现层)
- OSI/RM各层的功能
- 模板实现单向链表
- 2016年3月90号渗透学习总结
- redmine + apache + mod_fcgid
- c++ 模板实现顺序表