白盒测试
题 1:根据输入执行下列不同的数学计算并显示结果。编写程序,并设计测 试数据进行语句覆盖测试。输入数据打印出“输入 x 值:”、“输入 k 值:”。 执行算式一log(x ? k) 输出文字“算式一值:”和 y 的值,执行 k x 输出文字“算 式二值:”和 y 的值;执行 k x 输出文字“算式三值:”和 y 的值。其中变量 x、k 均须为正整数,若 x≤0 或 k≤0,则提示:“输入不符合要求。”;若 x≥30, 则提示:“数据超过范围。”。
package com.cao;
import java.lang.Math;
import java.util.Scanner;
public class first {
public static void main(String[] args) {
int x=0;
int k=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入x的值");
while (scanner.hasNext()){
try {
x =scanner.nextInt();
System.out.println("输入k的值");
k=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("输入不符合要求");
return;
}
}
if(x>0&&x<10){
System.out.println("算式一的值"+Math.log(x*k));
}else if(x>=10&&x<20){
System.out.println("算式二的值"+Math.pow(x,k));
}else if(x>=10&&x<30){
System.out.println("算式三的值"+Math.pow(x,1d/k));
}else if(x<0||k<0){
System.out.println("输入不符合要求");
}else {
System.out.println("数据超过范围");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class two {
public static void main(String[] args) {
int x=0;
int m=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入x值");
while (scanner.hasNext()){
try{
x =scanner.nextInt();
System.out.println("输入m值");
m=scanner.nextInt();
break;
}catch (Exception e) {
System.out.println("输入不符合要求");
return;
}
}
if((x>=0&&x<5)&&(m>0&&m<4)){int i=1;
System.out.println(Math.log(x));
}else if ((5<=x&&x<=10)&&(4<=m&&m<8)){
System.out.println(2*Math.sqrt(x/m));
}else if(x>10&&m>=8){
System.out.println(Math.pow(x,m+4));
}else {
System.out.println("输入不符合要求");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class three {
public static void main(String[] args) {
int x = 0;
int k = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("输入x的值");
while (scanner.hasNext()) {
try {
x = scanner.nextInt();
System.out.println("输入k的值");
k = scanner.nextInt();
break;
} catch (Exception e) {
System.out.println("输入不符合要求");
return;
}
}
if(x<0||k<0){
System.out.println("输入不符合要求");
}else if(0<x&&30>=x){
System.out.println("算式三的值"+Math.sin(x));
}else if(30<x&&60>=x){
System.out.println("算式三的值"+Math.cos(Math.pow(x,k)));
}else if(x>60){
System.out.println("算式三的值"+Math.tan(x));
}else {
System.out.println("输入不符合要求");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class four {
public static void main(String[] args) {
int x = 0;
int y= 0;
Scanner scanner = new Scanner(System.in);
System.out.println("输入x的值");
System.out.println("输入k的值");
while (scanner.hasNext()) {
try {
x = scanner.nextInt();
y = scanner.nextInt();
break;
} catch (Exception e) {
System.out.println("输入不符合要求");
return;
}
}
if(x<=0||y<=0){
System.out.println("输入不符合要求");
}else if(x==y){
System.out.println("可以构建圆形或正方形");
}else if(2<Math.abs(x-y)&&Math.abs(x-y)<=5){
System.out.println("可以构建椭圆");
}else if(0<Math.abs(x-y)&&Math.abs(x-y)<=2){
System.out.println("可以构建长方形");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class five {
public static void main(String[] args) {
int a = 0;
int b= 0;
Scanner scanner = new Scanner(System.in);
System.out.println("输入a的值");
while (scanner.hasNext()) {
try {
a = scanner.nextInt();
System.out.println("输入b的值");
b = scanner.nextInt();
break;
} catch (Exception e) {
System.out.println("输入不符合要求");
return;
}
}
if(a>5&&b>10){
double x =Math.pow(a,2)*2;
System.out.println("x="+x);
}else {
if(b==0 &&a >0){
double y=Math.sqrt(a);
System.out.println("y="+y);
}else{
double z=Math.pow((a+b),5);
System.out.println("z="+z);
}
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class six {
public static void main(String[] args) {
int a=0;
int b=0;
int c=0;
int d=0;
double Y=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入a值:");
while (scanner.hasNext()){
try {
a=scanner.nextInt();
System.out.println("输入b值:");
b=scanner.nextInt();
System.out.println("输入c值:");
c=scanner.nextInt();
System.out.println("输入d值:");
d=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("必须输入整数");
return;
}
}
System.out.println(a+b+c+d);
if((a>12&&b<13)&&(c>4||d<20)){
Y=3*a+10*b+5*d-c;
System.out.println("Y:"+Y);
}else {
Y=10*d-Math.pow((a+b),(c/5));
System.out.println("Y:"+Y);
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class seven {
public static void main(String[] args) {
int a=0;
int b=0;
double c=0;
Scanner scanner =new Scanner(System.in);
System.out.println("输入a的值:");
while (scanner.hasNext()){
try {
a=scanner.nextInt();
System.out.println("输入b的值:");
b=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("必须输入非零的整数");
return;
}
}
if(a!=0&&b!=0){
if(a>0&&b>0){
c=Math.sin(a+b*10);
System.out.println("算式一值:"+c);
System.out.println("c:"+c);
}else {
if(a<0&&b<0){
c=Math.pow((a*b),3);
System.out.println("算式二值:"+c);
System.out.println("c:"+c);
}else {
c=Math.pow((a-b),2);
System.out.println("算式三值:"+c);
System.out.println("c:"+c);
}
}
}else {
System.out.println("必须输入非零的整数");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class eight {
public static void main(String[] args) {
double x=0;
double y=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入x值");
x=scanner.nextDouble();
System.out.println("输入y值");
y=scanner.nextDouble();
if (x>60&&y<35){
double j=10*x-y;
System.out.println("j="+j);
}else {
if(x==25&&y>50){
double j=y*Math.log(x+10);
System.out.println("j="+j);
}else {
double j=(x-y)*(Math.pow(10,6)%7);
System.out.println("j="+j);
}
}
scanner.close();
}
}
package com.cao;
import javax.security.auth.login.LoginException;
import java.util.Scanner;
public class neight {
public static void main(String[] args) {
boolean name=false;
Scanner scanner=new Scanner(System.in);
System.out.println("请输入用户名:");
String username=scanner.next();
System.out.println("请输入密码:");
String passwordd=scanner.next();
try{
if(username.length()==8&&username.length()<9){
for(int i=0;i<username.length();i++){
char ch=username.charAt(i);
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='B')){
name=true;
}else {
name=false;
throw new LoginException("用户名错误");
}
}
}else {
throw new LoginException("用户名错误");
}if (name){
if(passwordd.length()>=6){
for(int i=0;i<passwordd.length();i++){
char ch=passwordd.charAt(i);
if(ch >= '0' && ch <= '9'){
}else {
throw new LoginException("密码错误");
}
}
}else {
throw new LoginException("密码错误");
}
System.out.println("用户名密码正确");
}
}catch (LoginException e){
System.out.println(e.getMessage());
}
scanner.close();
}
}
package com.cao;
import javax.security.auth.login.LoginException;
import java.util.Scanner;
public class login {
public static void main(String[] args) {
String address;
String phone;
Boolean statu=false;
Boolean pstatu=false;
Scanner scanner=new Scanner(System.in);
System.out.println("输入address:");
address=scanner.nextLine();
System.out.println("输入phone:");
phone=scanner.nextLine();
try {
if(phone.length()==11){
for (int i=0;i<phone.length();i++){
char ch;
ch=phone.charAt(i);
if(ch>='0'&&ch<='9'){
pstatu=true;
}else {
throw new LoginException("电话格式错误");
}
}
}else {
pstatu=false;
}
if(address.length()>0&&address.length()<=10){
for (int i=1;i<address.length();i++){
char ch;
char ch2;
ch=address.charAt(0);
ch2=address.charAt(i);
if(ch>='a'&&ch<='j'||ch>='A'&&ch<='J'){
if((ch2>'a'&&ch2<'j')||(ch2>'0'&&ch<'9')||ch2>='A'&&ch2<='J'){
statu=true;
}
}
}
}else {
statu=false;
}
}catch (LoginException e){
System.out.println(e.getMessage());
}
if(pstatu==true){
System.out.println("电话正确");
}else {
System.out.println("电话错误");
}
if(statu==true){
System.out.println("地址正确");
}else {
System.out.println("地址错误");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class eleven {
public static void main(String[] args) {
int x=0;
int y=0;
int z=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入x值:");
while (scanner.hasNext()){
try {
x=scanner.nextInt();
System.out.println("输入y值:");
y=scanner.nextInt();
System.out.println("输入z值:");
z=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("输入不符合规则");
return;
}
}
if(y>2&&z==0){
x=x/y;
System.out.println("x="+x);
}if(y==2&&x>1){
x=x+1;
y=x+2;
System.out.println("y="+y);
}else {
y=x+z;
System.out.println("y="+y);
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class twehlv {
public static void main(String[] args) {
int y=0;
Scanner scanner=new Scanner(System.in);
System.out.println("请输入年份:");
y=scanner.nextInt();
if(y%4==0&&y%100!=0){
System.out.println("leap year");
}else if(y%100==0&&y%400==0){
System.out.println("Century leap year");
}else {
System.out.println("It is not a leap year.");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class Thiretheen {
public static void main(String[] args) {
int x=0;
int y=0;
int a=-1;
int b=-1;
Scanner scanner=new Scanner(System.in);
System.out.println("输入x值");
while (scanner.hasNext()){
try {
x=scanner.nextInt();
System.out.println("输入y值");
y=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("请按要求输入x,y");
return;
}
}
if(x>0||y>0) {
a = 10;
if(x<10||y<10) {
b=0;
}
}else {
if(x<10||y<10) {
b=0;
}
}
System.out.println("a="+a);
System.out.println("b="+b);
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class fourtheen {
public static void main(String[] args) {
int a=0;
int b=0;
int x=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入a值");
while (scanner.hasNext()){
try {
a=scanner.nextInt();
System.out.println("输入b值");
b=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("输入不符合规范");
return;
}
}
System.out.println(a+b);
if(a>9&&b>5){
x=a*a*b;
System.out.println(x);
}else {
if(a<0&&b<0){
x=a-b;
System.out.println(x);
}else {
x=a+b;
System.out.println(x);
}
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class fifteen {
public static void main(String[] args) {
int x = 0;
int y = 0;
int a = 0;
int sum=0;
Scanner scanner = new Scanner(System.in);
System.out.println("输入x值");
while (scanner.hasNext()) {
try {
x = scanner.nextInt();
System.out.println("输入y值");
y = scanner.nextInt();
break;
} catch (Exception e) {
System.out.println("输入不符合规范");
return;
}
}
while (x>0){
if(y==0){
x=y+1;
break;
}else {
if(y==1){
a=y+10+a;
sum++;
System.out.format("a第%d次循环的值:%d",sum,a);
x=x-1;
}else {
a=y+20+a;
sum++;
System.out.format("a第%d次循环的值:%d\n",sum,a);
x=x-1;
}
}
}
x=x+1;
System.out.println("x="+x);
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class sixteen {
public static void main(String[] args) {
String username;
String password;
Scanner scanner=new Scanner(System.in);
System.out.println("输入用户名");
username=scanner.nextLine();
System.out.println("输入密码");
password=scanner.nextLine();
if (username.isEmpty()&&password.isEmpty()){
}else if(username.equals("admin")&&password.equals("123")){
System.out.println("登录成功");
}else if(!(username.equals("admin"))&&password.equals("123")){
System.out.println("请输入正确的用户名");
}else if(username.equals("admin")&&!(password.equals("123"))){
System.out.println("请输入正确的密码");
}else if(!(username.equals("admin"))&&!(password.equals("123"))){
System.out.println("请输入正确的用户名和密码");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class seventeen {
public static void main(String[] args) {
int y = 0;
int m = 0;
int d = 0;
int flag = 1;
Scanner scanner = new Scanner(System.in);
System.out.println("输入年:");
while (scanner.hasNext()){
try {
y=scanner.nextInt();
System.out.println("输入月:");
m=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("必须为正整数");
}
}
if(y>0){
switch (m){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
d=31;
break;
case 4:
case 6:
case 9:
case 11:
d=30;
break;
case 2:
if(y%4==0&&y%100!=0||y%400==0){
d=29;
}
else{
d=28;
}
break;
default:
flag=0;
}
if (flag == 0) {
System.out.println("月份错误");
} else {
System.out.format("%d年%d月有%d天!\n", y, m, d);
}
}else {
System.out.println("年份错误,必须为正整数");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class eightheen {
public static void main(String[] args) {
int a=0;
int b=0;
int c=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入a值");
while (scanner.hasNext()){
try {
a=scanner.nextInt();
System.out.println("输入b值");
b=scanner.nextInt();
System.out.println("输入c值");
c=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("输入不符合规则");
return;
}
}
if((1<=a&&a<=10)&&(1<=b&&b<=10)&&(1<=c&&c<=10)){
if(a+b>c||a+c>b||b+c>a){
if (a==b||a==c||b==c){
System.out.println("能组成等腰三角行");
}else if((a==b&&b==c)){
System.out.println("能组成等边三角形");
}else {
System.out.println("能组成普通三角形");
}
} else{
System.out.println("输入边值不能组成三角形");
}
}else{
System.out.println("输入边值不在范围内,请重新输入");
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class neighteen {
public static void main(String[] args) {
double a=0;
double b=0;
double c=0;
double d=0;
int x=0;
int y=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入x值:");
while (scanner.hasNext()){
try {
x=scanner.nextInt();
System.out.println("输入y值:");
y=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("输入必须为整形");
return;
}
}
System.out.println(x+y);
if(x>9&&y>4){
if(x>20||y>10){
c=Math.sin(x+y);
System.out.println("c的值:"+c);
}else {
d=Math.pow((x+5),5);
System.out.println("d的值:"+d);
}
}else{
if (x>0||y>0){
a=Math.pow(x,y);
System.out.println("a的值:"+a);
}else {
b=x+y;
System.out.println("b的值:"+b);
}
}
scanner.close();
}
}
package com.cao;
import java.util.Scanner;
public class twenty {
public static void main(String[] args) {
int x=0;
int y=0;
int a=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入x值:");
while (scanner.hasNext()){
try {
x=scanner.nextInt();
System.out.println("输入y值:");
y=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("必须输入整数");
break;
}
}
System.out.println(x+y);
if(x>=80&&x>=60){
if(x>=90||y>=90){
return;
}else {
a=2;
System.out.println("a="+a);
}
}else {
if(x<=70||y<=70){
a=4;
System.out.println("a="+a);
}else {
a=4;
System.out.println("a="+a);
}
}
scanner.close();
}
}
int x=0;
int y=0;
int a=0;
Scanner scanner=new Scanner(System.in);
System.out.println("输入x值:");
while (scanner.hasNext()){
try {
x=scanner.nextInt();
System.out.println("输入y值:");
y=scanner.nextInt();
break;
}catch (Exception e){
System.out.println("必须输入整数");
break;
}
}
System.out.println(x+y);
if(x>=80&&x>=60){
if(x>=90||y>=90){
return;
}else {
a=2;
System.out.println("a="+a);
}
}else {
if(x<=70||y<=70){
a=4;
System.out.println("a="+a);
}else {
a=4;
System.out.println("a="+a);
}
}
scanner.close();
}
}
|