结对编程--fault,error,failure的程序设计

一.结对编程内容:

  1.不能触发Fault。

  2.触发Fault,但是不触发Error。

  3.触发Error,但不触发Failure。

二.结对编程人员

  1.周浩,周宗耀

  2.结对截图:

三.结对项目编程

  1.不能触发Fault:  

 1 package com.hao_mini.www;
 2 
 3 import java.util.Scanner;
 4 
 5 public class True {
 6 
 7     public static void main(String[] args) {
 8         Scanner in=new Scanner(System.in);
 9         int i=in.nextInt();
10         int[] TrueArray=new int[i];
11         for(int j=0;j<TrueArray.length;j++){
12             TrueArray[j]=in.nextInt();
13         }
14         for(int j=0;j<TrueArray.length;j++){
15         System.out.println(TrueArray[j]);
16         }
17         in.close();
18     }
19 
20 }

  2.触发Fault,但是不触发Error:

 1 package com.hao_mini.www;
 2 
 3 import java.util.Scanner;
 4 
 5 public class Nofault {
 6     public static void main(String[] args) {
 7         Scanner in=new Scanner(System.in);
 8         int i; 9 i=in.nextInt(); 10 int counti=0; 11 for(int j=1;j<i;j++){ 12 counti++; 13  } 14  System.out.println(counti); 15  in.close(); 16  } 17 }

 

    分析:在11行  for(int j=1;j<i;j++){  触发了Fault,但并未造成Error

 

  3.触发Error,但不触发Failure:

1 package com.hao_mini.www;
 2 
 3 import java.util.Scanner;
 4 
 5 public class HaveFaultNotError {
 6 
 7     public static void main(String[] args) {
 8         Scanner in=new Scanner(System.in);
 9         
10         System.out.println("请输入长度"); 11 int i=in.nextInt(); 12 int[] TestArray=new int[i]; 13 int sum=0,j=0; 14 for(;j<TestArray.length-1;j++){ 15 TestArray[j]=in.nextInt(); 16 sum+=TestArray[j]; 17  } 18 int avg=sum/j; 19 System.out.println("avg="+avg); 20  in.close(); 21  } 22 23 }

  分析:在 14 行到17行  for(;j<TestArray.length-1;j++){ }处存在Error,并且触发了Error(sum=6 预期中间变量sum=9) , Failure((预期avg=sum(9)/3=3)

实际avg=sum(6)/2)  未触发。

 

四.分析与总结

  在这次结对中,更深入的认识到了这三者的关系,并逐渐接受了结对编程的编程思想。

转载于:https://www.cnblogs.com/hao-mini/p/5409090.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值