# 软件测试-边界值 **Repository Path**: deng-yongsheng/software-test-edge-value ## Basic Information - **Project Name**: 软件测试-边界值 - **Description**: 软件测试-黑盒测试-边界值分析 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-05-25 - **Last Updated**: 2022-06-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 软件测试-黑盒测试3 ## 需求 ### English A function/method taking one parameter: a real (floating point) number r. It considers a set of five other real numbers, which we'll call a1, a2, a3, a4 and a5, and it finds the largest one that is less than or equal to r. It subtracts this number from r and returns the result. For the purposes of this assessment, you must pick these five numbers yourself. You can pick whichever ones you want, as long as they are all different. ### 翻译 实现一个参数的函数/方法:实数(浮点)r。它考虑一组其他五个实数,参数名为a1,a2,a3,a4和a5,找到小于或等于r的最大值,从r中减去数字并返回结果。 为了进行此评估,您必须自己选择这五个数字。你可以选择你想要的,就像 只要他们都不一样。 ## 实现 ```java package cn.dengyongsheng; import java.util.Scanner; class ParameterRIsTooSmall extends Exception { @Override public String toString() { return "提供的参数r太小了!"; } } public class Main { // 自定义的a1到a5 static float a1 = -10, a2 = -1, a3 = 0, a4 = 1, a5 = 10; public static float fun(float r) throws ParameterRIsTooSmall { if (a1 > r && a2 > r && a3 > r && a4 > r && a5 > r) { throw new ParameterRIsTooSmall(); } // 找到最大值 float[] a_val = {a1, a2, a3, a4, a5}; // max的初始值为负无穷 float a_max = Float.NEGATIVE_INFINITY; for (float a : a_val) { if (a <= r && a > a_max) { a_max = a; } } return r - a_max; } public static void main(String[] args) throws ParameterRIsTooSmall { Scanner in = new Scanner(System.in); System.out.print("请输入实数r:"); float input_r = in.nextFloat(); System.out.println("函数执行结果为:" + fun(input_r)); } } ```