1 回答
TA贡献1820条经验 获得超10个赞
在do-while循环中移动println和行:scanner.nextInt()
这是一个仅打印出方法名称的修改示例:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
menu();
}
public static void menu() {
Scanner scan = new Scanner(System.in);
boolean works = true;
do {
System.out.println(
"\n1 - Register Car\t2 - Register Client\t3 - Rent car\n4 - Returning car\t5 - Show list\t6 - Exit\n");
System.out.print("Input: ");
int operacao = scan.nextInt();
if (operacao == 1) {
System.out.println("cadVeiculo();");
} else if (operacao == 2) {
System.out.println("cadCliente();");
} else if (operacao == 3) {
System.out.println("locar();");
} else if (operacao == 4) {
System.out.println("devolver();");
} else if (operacao == 5) {
System.out.println("listar();");
} else if (operacao == 6) {
System.out.println("Goodbye!");
works = false;
}
} while (works);
scan.close();
}
}
用法示例:
1 - Register Car 2 - Register Client 3 - Rent car
4 - Returning car 5 - Show list 6 - Exit
Input: 1
cadVeiculo();
1 - Register Car 2 - Register Client 3 - Rent car
4 - Returning car 5 - Show list 6 - Exit
Input: 3
locar();
1 - Register Car 2 - Register Client 3 - Rent car
4 - Returning car 5 - Show list 6 - Exit
Input: 4
devolver();
1 - Register Car 2 - Register Client 3 - Rent car
4 - Returning car 5 - Show list 6 - Exit
Input: 6
Goodbye!
添加回答
举报