我正在构建一个简单的货币转换器,但是当我调用输入采用方法时,它会跳过输入并退出代码处理。
public class RupeeConverter {
static double x;
static String input;
public double dollar(){
double dollar = x*0.014;
return dollar;
}
public double Chineseyuan(){
double yen = x*0.1;
return yen;
}
public double pound(){
double pound = x*0.011;
return pound;
}
public double dirham(double dirham){
dirham = x*0.052;
return dirham;
}
public void questions(){
Scanner myObj = new Scanner(System.in);
System.out.println("Input the amount of money you would like to convert: ");
x = myObj.nextDouble();
System.out.println("The currency you would like to convert in: ");
input = myObj.nextLine();
}
public static void main (String[] args){
RupeeConverter myObj2 = new RupeeConverter();
myObj2.questions();
switch (input) {
case "Pound":
myObj2.pound();
break;
case "Yuan":
myObj2.Chineseyuan();
break;
case "Dollar":
myObj2.dollar();
break;
}
}
}
这是代码...请帮助!
它需要第一个输入...询问第二个问题,但是退出过程而没有对第二个问题进行任何输入。