【发布时间】:2015-05-01 09:04:14
【问题描述】:
我不明白这个错误是逻辑错误还是其他什么这里是编码“这个程序应该将里亚尔转换为用户使用多路 if-else 选择的货币
import java.util.Scanner;
public class Convert
{
public static void main (String[] args)
{
Scanner kb= new Scanner (System.in);
double riyal, c;
int opp;
System.out.println("Please enter the amount of money in Riyal: ");
riyal= kb.nextDouble();
System.out.println("Enter the currency option(1- Dollar, 2- Euro, 3- Yen): ");
opp= kb.nextInt();
if(opp==1)
c=riyal*0.267;
System.out.print(riyal+" Riyals is converted to "+c" Dollars");
else if (opp==2)
c=riyal*0.197;
System.out.print(riyal+" Riyals is converted to "+c" Euros");
else if (opp==3)
c=riyal*0.27.950;
System.out.print(riyal+" Riyals is converted to "+c" Yens");
else
{
System.out.println("Invalied opption");
}
}
}
错误信息:
error: illegal start of expression
error: 'else' without 'if'
error: ';' expected
error: ')' expected
我使用的程序是Jcreator
【问题讨论】:
-
郑重声明,我不觉得你真的试图自己解决这个错误,你不应该得到那么多答案。尤其是那些顶级用户。
-
你遇到了什么错误?
-
@Md.NasirUddinBhuiyan:错误信息在问题的最后。
-
你应该学习 if-else 语句的基础知识。要在 if else 中使用多个语句,您必须在 if 条件下用 {} 覆盖该语句。
标签: java if-statement logic