⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ifelsetest.java

📁 java编程思想第四版习题答案
💻 JAVA
字号:
// control/IfEsleTest.java
// TIJ4 Chapter Control, Exercise 6, page 144
/* Modify the two test() methods in the previous two programs so that they take
* two extra arguments begin and end, and so that testval is tested to see if it
* is within the range between (and including) begin and end.
*/

import static net.mindview.util.Print.*;

public class IfElseTest {
	static int test(int testval, int begin, int end) {
		if(end < begin) {
			print("end cannot be < begin");
			return 0;
		}
		if((testval > (begin - 1)) && (testval < (end + 1)))
			return +1;
		if((testval < begin) || (testval > end))
			return -1;
		print("exceptional case");
		return 13;
	}
	public static void main(String[] args) {
		print(test(10, 5, 4));
		print(test(5, 4, 10));
		print(test(5, 5, 6));
		print(test(10, 5, 7));
		print(test(5, 5, 5));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -