編寫一個允許用戶輸入多個值的程序,然後該程序應該將以磅(GBP)輸入的值轉換爲多種不同的貨幣。菜單應該是這個樣子:將arraylist中的每個數字相乘
- 輸入值和類型-1停止
- 歐元
- 美元
- 日元
- 盧比
- 退出
2時,3,4或5被選中時,程序應該顯示在原磅和公司中輸入的每個值兌換貨幣,以及所有數字和兌換總數。
public class Money {
public static void main(String[] args) {
System.out.println("Enter values and type -1 to stop");
System.out.println("'1' = Euros");
System.out.println("'2' = Dollars");
System.out.println("'3' = Yen");
System.out.println("'4' = Rupees");
System.out.println("'5' = Exit");
int count=0;
String exit = "-1", euro="E";
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.print("Convert to: ");
while (!scan.hasNext("[E, D, Y, R, X]+")) {
System.out.print("Invalid value, enter Surname again: ");
scan.next();
}
String exTo = scan.next();
ArrayList<String> num = new ArrayList<String>();
while (true) {
count++;
System.out.print("|| Enter values "+count+" in (P)Pounds : ");
while (!scan.hasNextDouble()) {
System.out.print("Invalid value, try again: ");
scan.next();
}
num.add(scan.next());
if(num.contains(exit)){
String ar[]=num.toArray(new String[num.size()]);
ar=num.toArray(ar);
System.out.println("Result: "+ num);
scan.close();
break;
}
}
}
}
什麼問題。 ? – Arpit
如何乘以每個數字內數組列表等 用戶鍵入數字內部數組列表 陣列看起來像這樣:[20,30,40] 和後我需要像每個數字結果顯示乘以2例如 [40,60,80] –
))))或者任何其他方式從用戶收集數字,例如將它們保存在數組中並顯示所有數字乘以選擇的值 –