【发布时间】:2017-04-02 13:24:06
【问题描述】:
我用一些方法实现了一个 java 程序。接下来我创建了一个主类,它将通过输入一个单词来调用相关的方法。
例如:
Enter {A|B|C|D|E} to call method. A=method one B = method two...etc
A<--this is the user input
Enter Number:<--the first Scanner input of method A
123<--Input 1
Enter words:<-- the second Scanner input of method A
ABC<--Input 2
123ABC<--The output method A
Enter {A|B|C|D|E} to call method. A=method one B = method two...etc
B<--this is the user input
Enter Number 1:<--the first Scanner input of method B
100<--Input 1
Enter Number 2:<-- the second Scanner input of method B
50<--Input 2
150<--The output method B
Code of Method A {
String output;
private static Scanner keyboard = new Scanner(System.in);
System.out.println("Enter Number:");
String no = keyboard.nextLine();
System.out.println("Enter Words:");
String words = keyboard.nextLine();
//do something...
System.out.println(output);
}
Code of Main class{
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args){
Main main = new Main();
main.run();
}
public void run() {
boolean running = true;
while (running) {
displayMenu();
String command = keyboard.nextLine();
String[] parts = command.split("^");
if ("A".equalsIgnoreCase(command)) {
//call method A
} else if ("B".equalsIgnoreCase(command)) {
//call method B
} else if....etc
System.out.println();
}
我想要的是输入
A
123 , ABC
B
100,50 一次
然后系统将为我打印方法 A (123ABC) 和 B (150) 的输出。
我想要的是在“键盘”中输入A,在“no”中输入123,在“words”中输入ABC
我该怎么做?
【问题讨论】:
-
我希望我的回答对您有所帮助,但您应该在以后提出更具体的问题。您的明确问题是“有可能”,答案是“是”。但是,我们不知道您在实施可行的解决方案时缺少什么,而且您很难找到愿意为您生成整个代码的人。
-
感谢您的回答。我改变了我的问题,所以它会更具体