5.2
import java.util.Random; public class test { private int a; private int b; int c; public int jia(int a,int b) { System.out.println(""+a); System.out.println(""+b); c = a+b; System.out.println("a+"+"b"+"="+(a+b+"\n")); return c; } public int jian(int a,int b) { System.out.println(""+a); System.out.println(""+b); c=a-b; System.out.println("a-"+"b"+"="+(a-b)+"\n"); return c; } public int Cheng(int a,int b) { System.out.println(""+a); System.out.println(""+b); c=a*b; System.out.println("a*"+"b"+"="+(a*b)+"\n"); return c; } public double Chu(int a,int b) { double c; c=(double) (Math.round((a/b)*100/100.0)); System.out.println(""+a); System.out.println(""+b); if(b!=0) System.out.println("c=a/b="+(c)+"\n"); else throw new ArithmeticException(); System.out.println("分母不能为0!"); return c; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub test Jia=new test(); Jia.jia(5, 3); test Jian=new test(); Jian.jian(6,2); test cheng=new test(); cheng.Cheng(6,5); test chu=new test(); chu.Chu(3,0); } }
import java.util.Random; public class FZ { private int a; private int b; int c; public int jia(int a,int b) { System.out.println(""+a); System.out.println(""+b); c = a+b; System.out.println("a+"+"b"+"="+(a+b+"\n")); return c; } public int jian(int a,int b) { System.out.println(""+a); System.out.println(""+b); c=a-b; System.out.println("a-"+"b"+"="+(a-b)+"\n"); return c; } public int Cheng(int a,int b) { System.out.println(""+a); System.out.println(""+b); c=a*b; System.out.println("a*"+"b"+"="+(a*b)+"\n"); return c; } public double Chu(int a,int b) { double c; c=(double) (Math.round((a/b)*100/100.0)); System.out.println(""+a); System.out.println(""+b); if(b!=0) System.out.println("c=a/b="+(c)+"\n"); else throw new ArithmeticException(); System.out.println("分母不能为0!"); return c; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub FZ Jia=new FZ(); Jia.jia(5, 3); FZ Jian=new FZ(); Jian.jian(6,2); FZ cheng=new FZ(); cheng.Cheng(6,5); FZ chu=new FZ(); chu.Chu(3,0); } }
总结:了解了测试后发现测试是一个很好的功能,它能及时发现错误,提高开发效率。
如果对测试还不是很懂的同学可以在慕课网学习,那里有详细方法。