auf Java ziemlich neu zu sein, habe ich dieses Programm geschrieben haben verschiedene Währungen zu berechnen. Ich möchte den Benutzer fragen, ob er den Prozess wiederholen möchte, bis der Benutzer es beenden möchte. Bitte helfen Sie mir in dieser Angelegenheit. Mein Code so weit:Implementierung tun, während und Ausfahrt
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat formatter = new DecimalFormat("#0.00");
String CType, c1 = "US", c2 = "EUR", c3 = "RM", c4 = "SAR";
double CValue , US, EUR, RM, SGD, SAR;
System.out.println("Welcome to Bonus Calculator");
System.out.println("Enter any of the following Currencies:");
System.out.print("US\n" +
"EUR\n" +
"RM\n" +
"SGD\n" +
"SAR: ");
CType = input.next();
if(CType.equalsIgnoreCase("US")){
System.out.print("Enter Value: ");
CValue = input.nextInt();
EUR = CValue * .88;
RM = CValue * 3.92;
SGD = CValue * 1.35;
SAR = CValue * 3.75;
System.out.print("US = " + formatter.format(CValue) + "EUR =" + formatter.format(EUR) + "RM =" + formatter.format(RM) + "SGD =" + formatter.format(SGD) + "SAR =" + formatter.format(SAR));
}
else if(CType.equalsIgnoreCase("EU")){
System.out.print("Enter Value: ");
CValue = input.nextInt();
US = CValue * 1.14;
RM = US * 3.92;
SGD = US * 1.35;
SAR = US * 3.75;
System.out.print("EUR = " + formatter.format(CValue) + " US = " + formatter.format(US) + " RM = " + formatter.format(RM) +" SGD = " + formatter.format(SGD) +" SAR = " + formatter.format(SAR));
}
else if (CType.equalsIgnoreCase("RM")){
System.out.print("Enter Value: ");
CValue = input.nextInt();
US = CValue * .26;
EUR = US * .88;
SGD = US * 1.35;
SAR = US * 3.75;
System.out.print("RM = " + formatter.format(CValue) + " US = " + formatter.format(US) + " EUR = " + formatter.format(EUR) + " SGD = " + formatter.format(SGD) + " SAR = " + formatter.format(SAR));
}
else if (CType.equalsIgnoreCase("SGD")){
System.out.print("Enter Value: ");
CValue = input.nextInt();
US = CValue * 0.74;
EUR = US * .88;
RM = US * 3.92;
SAR = US * 3.75;
System.out.print("SGD = " + formatter.format(CValue) + " US = " + formatter.format(US) + " EUR = " + formatter.format(EUR) + " SAR = " + formatter.format(SAR) + " RM = " + formatter.format(RM));
}
else if(CType.equalsIgnoreCase("SAR")){
System.out.print("Enter Value: ");
CValue = input.nextInt();
US = CValue * 0.39;
EUR = US * .88;
RM = US * 3.92;
SGD = US * 1.35;
System.out.print("SAR = " + formatter.format(CValue) + " US = " + formatter.format(US) + " EUR = " + formatter.format(EUR) + " SGD = " + formatter.format(SGD) + " RM = " + formatter.format(RM));
}
}
Also, wo ist das Problem? Sie haben Java bereits im Griff, was ist mit einer Schleife los? – Thomas
Ich bin verwirrt darüber, wo und wie man den Benutzer fragen kann, ob er einen anderen Wert eingeben und beenden möchte, wenn nicht. Ich weiß aus dem Code sind Nähte wie sollte das wissen. Aber ich bin verloren. –