作业5.2
package Test; import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class sizeyunsuan {
public static void main(String[] args) {
String condition = "";
int x,y;
String z ,p,p1;
Scanner inr = new Scanner(System.in);
BufferedReader in=new BufferedReader(new InputStreamReader(System.in)) ;
do{
System.out.print("请输入第一个数字:") ;
while(true)
{
try
{
p=in.readLine();
x=Integer.parseInt(p);
if(x>-1000||x<1000)
{
System.out.println("\n") ;
}
break;
}
catch(Exception e)
{
System.out.println("\n错误") ;
}
}
System.out.print("请输入第二个数字:") ;
while(true)
{
try
{
p1=in.readLine();
y=Integer.parseInt(p1);
if(y>-1000||y<1000)
{
System.out.println("\n") ;
}
break;
}
catch(Exception e)
{
System.out.println("\n错误") ; } } System.out.println("请输入运算符(+,-,*,/):");
z = inr.nextLine();
System.out.println("\n"+x+" "+z+" "+y+"=");
core test = new core();
test.yunsuan(z, x, y);
System.out.print("是否继续?Y:继续,任意字符:结束");
condition = inr.nextLine();
}while("Y".equals(condition));
}
}
import java.io.InputStreamReader;
import java.util.Scanner;
public class sizeyunsuan {
public static void main(String[] args) {
String condition = "";
int x,y;
String z ,p,p1;
Scanner inr = new Scanner(System.in);
BufferedReader in=new BufferedReader(new InputStreamReader(System.in)) ;
do{
System.out.print("请输入第一个数字:") ;
while(true)
{
try
{
p=in.readLine();
x=Integer.parseInt(p);
if(x>-1000||x<1000)
{
System.out.println("\n") ;
}
break;
}
catch(Exception e)
{
System.out.println("\n错误") ;
}
}
System.out.print("请输入第二个数字:") ;
while(true)
{
try
{
p1=in.readLine();
y=Integer.parseInt(p1);
if(y>-1000||y<1000)
{
System.out.println("\n") ;
}
break;
}
catch(Exception e)
{
System.out.println("\n错误") ; } } System.out.println("请输入运算符(+,-,*,/):");
z = inr.nextLine();
System.out.println("\n"+x+" "+z+" "+y+"=");
core test = new core();
test.yunsuan(z, x, y);
System.out.print("是否继续?Y:继续,任意字符:结束");
condition = inr.nextLine();
}while("Y".equals(condition));
}
}
package Test; public class core { public void yunsuan(String cc, double a, double b) { js test1 = new js(); if (cc.equals("+")) { test1.jia(a , b); } else if (cc.equals("-")) { test1.jian(a , b); } else if (cc.equals("*")) { test1.cheng(a , b); } else if (cc.equals("/")) { if (b != 0) { test1.chu(a , b); } else { System.out.println("被除数不能为0!"); throw new ArithmeticException(); } } else { System.out.println("运算符不符合!"); } } }
package Test; public class js { /** * @param args */ public static double jia( double a, double b) { double result=0; result=a+b; System.out.println(a +"+"+ b); System.out.println(result); return result; } public static double jian( double a, double b) { double result=0; result=a-b; System.out.println(a +"-"+ b); System.out.println(result); return result; } public static double cheng( double a, double b) { double result=0; result=a*b; System.out.println(a +"*"+ b); System.out.println(result); return result; } public static double chu( double a, double b) { double result=0; result=a/b; System.out.println(a +"/"+ b); System.out.println(result); return result; } }
总结:这次的作业是一次挑战,老师上课说的东西并不能完全懂,但通过看书查资料更重要的是小伙伴的帮助下,才能慢慢白盒测试是清晰程序的思维,黑盒测试是为了帮助我们找到程序中的bug。