你好下面是我Progarm如何基於Java中使用掃描儀的用戶選擇重複循環
import java.util.Scanner;
public class Usecase1 {
public static void main(String[] args) {
Usecase1 us = new Usecase1();
us.withdrawl();
}
public void withdrawl() {
System.out.println("your Account number is....0091236452312");
System.out.println("please enter your pin number(1234)....");
Scanner sc = new Scanner(System.in);
int pinno = sc.nextInt();
if (pinno == 1234) {
System.out
.println("Please select type of Transaction 1.Balance Enquiry 2.Withdraw Money");
int option = sc.nextInt();
System.out.println("your choice is..." + option);
int totalamount = 85000;
if (option == 2) {
System.out.println("enter amount to withdraw");
int amount = sc.nextInt();
System.out.println("Remaining Balance in your account is..."
+ (totalamount - amount));
}
}
}
}
我的要求是,用戶可以給自己的選擇,因爲2任意次數,每一個下面的循環應時間請重複,請幫助我如何做到這一點。
(option == 2) {
System.out.println("enter amount to withdraw");
int amount = sc.nextInt();
System.out.println("Remaining Balance in your account is..."
+ (totalamount - amount));
}
使用'while循環'while(true){if(option == 2){//當沒有更多動作需要時執行s break和break}} – 2014-09-03 09:18:17
當選項中有'continue' == 2 – 2014-09-03 09:21:39