首页 > 解决方案 > 用其他方法启动各种方法

问题描述

我想用 Scanner 的其他方法启动各种方法(练习)。当机器询问哪些练习时,我想用敲击的答案来回答,当我说练习(方法)时,机器会用我的敲击答案来启动这个方法。

示例:
哪些练习?
me -“W34”
(机器启动方法 W34)

代码

标签: javamethods

解决方案


对不起,我不是专业人士,对不起,这是我在这个网站上的第一个问题,我只做一些练习,因为有这么多。

代码 :

公共类主要{

public static String CapitalizeEachWord(String st) {
    String result = "";
    st = st.replaceAll("() ([A-Z])", "$1 $2");
    String[] words = st.split(" ");
    for (String word : words)
        if (word.length() > 0)
            result += Character.toUpperCase(word.charAt(0)) + word.substring(1) + " ";
    return result;
}



public static String Scann() {
    Scanner in = new Scanner(System.in);
    System.out.println("Wich exercises? (W + exNumb)");
    int x = in.nextInt();






    return null;
}

public static String W1() {
    System.out.println("Hello");
    System.out.println("Antoine Sidot!");
    System.out.println();
    return null;
}
public static String W2() {
    int result = 74 + 36;
    System.out.println(result);
    return null;
}
public static String W3() {
    System.out.println(50/3);
    return null;
}
public static String W4() {
    System.out.println(-5 + 8 * 6);
    System.out.println((55 + 9) % 9);
    System.out.println(20 + -3*5 / 8);
    System.out.println(5 + 15 / 3 * 2 -8 % 3);
    return null;
}
public static String W5() {
    int nb1 = 25;
    int nb2 = 5;
    System.out.println(nb1 + " x " + nb2 + " = " + nb1*nb2);
    return null;
}

}


推荐阅读