gpt4 book ai didi

java - 代码中的枚举错误

转载 作者:行者123 更新时间:2023-11-30 03:20:52 26 4
gpt4 key购买 nike

这段代码是我写的但是当我尝试编译时它说:

 error: class, interface, or enum expected
}
^
1 error

我该如何解决这个问题?我不明白。括号里有问题吗?枚举是什么意思?我检查了括号,一切似乎都按顺序进行。

import java.util.Scanner;

public class Horoscope {
public static void main(String[] args) {

System.out.println("Please enter month of Birth: ");
Scanner month = new Scanner(System.in);
System.out.println("Please enter day of Birth: ");
Scanner day = new Scanner(System.in);
System.out.println("Your horoscope is ");

if ((month == 3 && day >= 21 && day <= 31) || (month == 4 && day >= 1 && day <= 19)) {
System.out.print("Aries");
}
if ((month == 4 && day >= 20 && day <= 30) || (month == 5 && day >= 1 && day <= 20)) {
System.out.print("Taurus");
}
if ((month == 5 && day >= 21 && day <= 31) || (month == 6 && day >= 1 && day <= 20)) {
System.out.print("Gemini");
}
if ((month == 6 && day >= 21 && day <= 30) || (month == 7 && day >= 1 && day <= 22)) {
System.out.print("Cancer");
}
if ((month == 7 && day >= 23 && day <= 31) || (month == 8 && day >= 1 && day <= 22)) {
System.out.print("Leo");
}
if ((month == 8 && day >= 23 && day <= 31) || (month == 9 && day >= 1 && day <= 22)) {
System.out.print("Virgo");
}
if ((month == 9 && day >= 23 && day <= 30) || (month == 10 && day >= 1 && day <= 22)) {
System.out.print("Libra");
}
if ((month == 10 && day >= 23 && day <= 31) || (month == 11 && day >= 1 && day <= 21)) {
System.out.print("Scorpio");
}
if ((month == 11 && day >= 22 && day <= 30) || (month == 12 && day >= 1 && day <= 21)) {
System.out.print("Sagittarius");
}
if ((month == 12 && day >= 22 && day <= 31) || (month == 1 && day >= 1 && day <= 19)) {
System.out.print("Capricorn");
}
if ((month == 1 && day >= 20 && day <= 31) || (month == 2 && day >= 1 && day <= 18)) {
System.out.print("Aquarius");
}
if ((month == 2 && day >= 19 && day <= 29) || (month == 3 && day >= 1 && day <= 20)) {
System.out.print("Pisces");
}
}
}
}
}

谢谢

最佳答案

通过使用 Scanner Month = new Scanner(System.in) 您只需告诉编译器仅使用 in 流。你必须说int mnth = Month.nextInt()更改这部分

System.out.println("Please enter month of Birth: ");
Scanner month = new Scanner(System.in);
System.out.println("Please enter day of Birth: ");
Scanner day = new Scanner(System.in);
System.out.println("Your horoscope is ");

int month=0 , day=0;
Scanner scanner= new Scanner(System.in);
System.out.println("Please enter month of Birth: ");
month = scanner.nextInt();
System.out.println("Please enter day of Birth: ");
day = scanner.nextInt();
System.out.println("Your horoscope is ");

关于java - 代码中的枚举错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31368123/

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