gpt4 book ai didi

java - token "else,"上的语法错误删除此 token

转载 作者:行者123 更新时间:2023-11-29 03:00:22 25 4
gpt4 key购买 nike

我是 java 的新手,我不明白为什么这里有语法错误。代码我已经复制粘贴了,错误的地方我也注释了。

import java.util.Scanner;
public class CountryDetails {
public static void main(String [] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter any of the following integers to see details of the corresponding country:(1, 36, 57, 94, 250, 269, 354, 376, 597, 678, 962, 992)");
//prompt reader to enter a number
int code=input.nextInt();

int x;
x=input.nextInt();
if ((x!=1)&&(x!=36)&&(x!=57)&&(x!=94)&&(x!=250)&&(x!=269)&&(x!=354)&&(x!=376)&&(x!=597)&&(x!=678)&&(x!=962)&&(x!=992)); {
System.out.println("You did not enter one of the possible integers.");
}

else if (x==1) { //error is here
System.out.println("Enter amount in US dollars:"); //prompt reader to enter US dollars
double dollars = input.nextDouble(); //reading input
double exchangeRate= dollars*45.72;

//display results
System.out.println ("1 is the Country Calling Code for the Dominican Republic, which is located in the Americas");
System.out.println (+dollars+ " is equivalent to " +exchangeRate+ "Dominican Pesos.");
}

谢谢!!

最佳答案

通过你的长 if 语句,去掉末尾的分号。

// The semicolon at the end of this line
if ((x!=1)&&(x!=36)&&(x!=57)&&(x!=94)&&(x!=250)&&(x!=269)&&(x!=354)&&(x!=376)&&(x!=597)&&(x!=678)&&(x!=962)&&(x!=992)); {
System.out.println("You did not enter one of the possible integers.");
}

关于java - token "else,"上的语法错误删除此 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35413868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com