在下面的代码中,如何将帮助程序的方法放入交换机中?
我尝试在声明帮助程序类之前将System.out.println
语句放入开关中,但它不起作用。
在不必过多更改代码的情况下,启动帮助程序类的最简单方法是什么?
public static void Check(double result){
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the 13 digits of the ISBN, seperating each one with the enter key: ");
String isbn = keyboard.next();
result = 0;
for(int x = 0; x < 14; x++) {
if (x% 2 != 0) {
double b = Character.getNumericValue(isbn.charAt(x));
double mul = (b*3);
result += mul;
}
}
public static double method(double[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a number for X:");
double x = keyboard.nextDouble();
double result = 0;
double number1 = 0;
do {
number1 = (6 * (Math.pow(x,4)) - 13 * (Math.pow(x, 3)) - 18 * (Math.pow(x,2)) + 7 * x + 6) / (24 * (Math.pow(x, 3)) - 39 * (Math.pow(x, 2)) - 36 * x + 7);
result = (x - number1);
x = result;
System.out.println(x);
} while (Math.abs(number1) >= 0.001);
System.out.println("the answer is:" + Math.round(result));
return result;
}
public static boolean formula(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a,b and c with the enter key between");
double a = keyboard.nextDouble();
double b = keyboard.nextDouble();
double c = keyboard.nextDouble();
double discriminant = b * b - 4 * a * c;
boolean good = false;
good = (discriminant < 0);
if (discriminant < 0) {
System.out.println("No roots :(");
} else if (discriminant == 0) {
System.out.println("The single root is : " + ((-b + Math.sqrt(discriminant)) / (2 * a)));
} else {
System.out.println("The single root is : " + ((-b + Math.sqrt(discriminant)) / (2 * a)));
System.out.println("The single root is : " + ((-b - Math.sqrt(discriminant)) / (2 * a)));
}
return good;
}
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("hi! if you want to do a ISBNnumber checker type: 1. If you want newton's meathod type: 2. If you want to check quadractic formula type: 3.");
int change = keyboard.nextInt();
switch (change) {
case 1: change = 1;
break;
case 2: change = 2;
break;
case 3: change = 3;
break;
}
}
}