java - 用其他方法启动各种方法
问题描述
我想用 Scanner 的其他方法启动各种方法(练习)。当机器询问哪些练习时,我想用敲击的答案来回答,当我说练习(方法)时,机器会用我的敲击答案来启动这个方法。
示例:
哪些练习?
me -“W34”
(机器启动方法 W34)
解决方案
对不起,我不是专业人士,对不起,这是我在这个网站上的第一个问题,我只做一些练习,因为有这么多。
代码 :
公共类主要{
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;
}
}
推荐阅读
- python - Python,Pandas:查找具有确切条件的第一行索引
- java - Java Swing:JTextPane 中的语法高亮
- postgresql - 从 Postgres 到 Rails 的哈希转换
- python - 查找 Dask 数据帧的长度
- vb.net - 从 ComboBox 中选择特定行并在 DataGridView VB.NET 的同一行中的其他列中添加金额
- json - jq 选择过滤器链
- reactjs - 迭代反应 ag-grid 的特定行
- java - 使用 copyProperties() 而不是自定义 Gson 序列化程序 - 值得吗?
- javascript - 单击按钮时更新图像源
- android - 如何在 Android 中用线条和三角形一起绘制球体?