【发布时间】:2015-10-02 02:43:36
【问题描述】:
您好,我正在做一个项目,我正在尝试找出我的代码有什么问题,以便正确打印。编写一个 Java 程序,提示用户输入他或她生日的日期和月份(均为整数),然后打印相应的占星符号。
public class Birthday {
public static void main(String args [] ) {
String birthday = System.console().readline("Enter your birthday, month then day.");
float value = Float.parseFloat(birthday);
if (month < 1 || month > 12) {
System.out.println("Invalid month please try again.");
}
else if (day < 1 || day > 31) {
System.out.println("Invalid day please try again.");
}
else if (month = 1 || month = 12) {
}
else if (day >= 22 || day <= 19); {
System.out.println(birthday + "Capricorn");
}
}
}
这些是我得到的错误:
Birthday.java:3: readline(boolean) in java.io.Console cannot be applied to (java.lang.String)
float birthday = System.console().readline("Enter your birthday, month then day.");
^
Horoscopes.java:4: cannot find symbol
symbol : variable month
location: class Birthday
if (month < 1 || month > 12) {
^
Horoscopes.java:4: cannot find symbol
symbol : variable month
location: class Birthday
if (month < 1 || month > 12) {
^
Horoscopes.java:8: cannot find symbol
symbol : variable day
location: class Birthday
else if (day < 1 || day > 31) {
^
Horoscopes.java:8: cannot find symbol
symbol : variable day
location: class Birthday
else if (day < 1 || day > 31) {
^
Horoscopes.java:12: cannot find symbol
symbol : variable month
location: class Birthday
else if (month = 1 || month = 12) {
^
Horoscopes.java:12: cannot find symbol
symbol : variable month
location: class Birthday
else if (month = 1 || month = 12) {
^
Horoscopes.java:16: cannot find symbol
symbol : variable day
location: class Birthday
else if (day >= 22 || day <= 19); {
^
Horoscopes.java:16: cannot find symbol
symbol : variable day
location: class Birthday
else if (day >= 22 || day <= 19); {
^
9 errors
【问题讨论】:
-
有什么问题?
-
我看不到你在哪里设置
month或day -
我不断收到错误。我找不到符号。
-
嗨。正确缩进你的代码。具体描述您遇到的问题。为您的问题使用一个合理的标题,以表明您的问题。
-
请添加您收到的错误消息和回溯。另外,请将标题更改为描述相关问题的内容。
标签: java validation date input user-input