提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
具有分支结构的功能
public class Main { public static void main(String[] arguments) { /*来自 nowjava - 时代Java*/ double x = Math.E; System.out.println("Choose function to evalute for x=" + x); System.out.print("(1) Identity, (2) Logarithm, (3) Sinus.Your choice ?"); System.out.println("F(x)=" + F(2, x)); } public static double F(int generator, double x) { double v = 0.0; /* N o w J a v a . c o m - 时 代 Java 提供 */ switch (generator) { case 1: v = x; break; case 2: v = Math.log(x);