Java 对于每个出生日,它都会键入;“第三十一条”;并说:";“日期名称”;没有用过吗? String MonthName=“”; 字符串DateName=“”; 字符串符号=”; 弦星象=”; 扫描仪扫描=新扫描仪(System.in); System.out.println(“请以整数形式输入您的出生月份:”; int month=scan.nextInt(); System.out.println(“”); System.out.println(“请以整数形式输入您的出生日期:”; int date=scan.nextInt(); System.out.println(“”); 如果(月份==1){ MonthName=“一月”; }否则,如果(月==2){ MonthName=“二月”; }否则,如果(月份==3){ MonthName=“三月”; }否则,如果(月==4){ MonthName=“四月”; }否则,如果(月==5){ MonthName=“May”; }否则,如果(月==6){ MonthName=“June”; }否则,如果(月==7){ MonthName=“七月”; }否则,如果(月==8){ MonthName=“八月”; }否则,如果(月==9){ MonthName=“九月”; }否则,如果(月==10){ MonthName=“十月”; }如果(月份==11),则为其他情况{ MonthName=“11月”; }否则,如果(月==12){ MonthName=“十二月”; } 如果(日期=1){ DateName=“first”; }否则,如果(日期==2){ DateName=“第二”; }否则,如果(日期==3){ DateName=“第三”; }否则,如果(日期==4){ DateName=“第四”; }否则,如果(日期==5){ DateName=“第五”; }否则,如果(日期==6){ DateName=“第六”; }否则,如果(日期==7){ DateName=“第七”; }否则,如果(日期==8){ DateName=“第八”; }否则,如果(日期==9){ DateName=“第九”; }否则,如果(日期==10){ DateName=“第十”; }否则,如果(日期=11){ DateName=“第十一”; }否则,如果(日期==12){ DateName=“第十二”; }否则,如果(日期==13){ DateName=“十三”; }否则,如果(日期==14){ DateName=“第十四”; }否则,如果(日期==15){ DateName=“十五”; }否则,如果(日期==16){ DateName=“第十六”; }否则,如果(日期==17){ DateName=“十七”; }否则,如果(日期==18){ DateName=“第十八”; }否则,如果(日期==19){ DateName=“第十九”; }否则,如果(日期==20){ DateName=“第二十”; }否则,如果(日期==21){ DateName=“twentyfirst”; }否则,如果(日期==22){ DateName=“二十秒”; }否则,如果(日期==23){ DateName=“二十三”; }否则,如果(日期==24){ DateName=“二十四”; }否则,如果(日期==25){ DateName=“二十五”; }否则,如果(日期==26){ DateName=“二十六”; }否则,如果(日期==27){ DateName=“第二十七”; }否则,如果(日期==28){ DateName=“二十八”; }否则,如果(日期==29){ DateName=“二十九”; }否则,如果(日期==30){ DateName=“第三十”; }否则,如果(日期==31); DateName=“thirtyfirst”; 如果((月=1)和&(日期=22)){ 符号=“摩羯座”; }如果((month==1)|(month==2)&(date

Java 对于每个出生日,它都会键入;“第三十一条”;并说:";“日期名称”;没有用过吗? String MonthName=“”; 字符串DateName=“”; 字符串符号=”; 弦星象=”; 扫描仪扫描=新扫描仪(System.in); System.out.println(“请以整数形式输入您的出生月份:”; int month=scan.nextInt(); System.out.println(“”); System.out.println(“请以整数形式输入您的出生日期:”; int date=scan.nextInt(); System.out.println(“”); 如果(月份==1){ MonthName=“一月”; }否则,如果(月==2){ MonthName=“二月”; }否则,如果(月份==3){ MonthName=“三月”; }否则,如果(月==4){ MonthName=“四月”; }否则,如果(月==5){ MonthName=“May”; }否则,如果(月==6){ MonthName=“June”; }否则,如果(月==7){ MonthName=“七月”; }否则,如果(月==8){ MonthName=“八月”; }否则,如果(月==9){ MonthName=“九月”; }否则,如果(月==10){ MonthName=“十月”; }如果(月份==11),则为其他情况{ MonthName=“11月”; }否则,如果(月==12){ MonthName=“十二月”; } 如果(日期=1){ DateName=“first”; }否则,如果(日期==2){ DateName=“第二”; }否则,如果(日期==3){ DateName=“第三”; }否则,如果(日期==4){ DateName=“第四”; }否则,如果(日期==5){ DateName=“第五”; }否则,如果(日期==6){ DateName=“第六”; }否则,如果(日期==7){ DateName=“第七”; }否则,如果(日期==8){ DateName=“第八”; }否则,如果(日期==9){ DateName=“第九”; }否则,如果(日期==10){ DateName=“第十”; }否则,如果(日期=11){ DateName=“第十一”; }否则,如果(日期==12){ DateName=“第十二”; }否则,如果(日期==13){ DateName=“十三”; }否则,如果(日期==14){ DateName=“第十四”; }否则,如果(日期==15){ DateName=“十五”; }否则,如果(日期==16){ DateName=“第十六”; }否则,如果(日期==17){ DateName=“十七”; }否则,如果(日期==18){ DateName=“第十八”; }否则,如果(日期==19){ DateName=“第十九”; }否则,如果(日期==20){ DateName=“第二十”; }否则,如果(日期==21){ DateName=“twentyfirst”; }否则,如果(日期==22){ DateName=“二十秒”; }否则,如果(日期==23){ DateName=“二十三”; }否则,如果(日期==24){ DateName=“二十四”; }否则,如果(日期==25){ DateName=“二十五”; }否则,如果(日期==26){ DateName=“二十六”; }否则,如果(日期==27){ DateName=“第二十七”; }否则,如果(日期==28){ DateName=“二十八”; }否则,如果(日期==29){ DateName=“二十九”; }否则,如果(日期==30){ DateName=“第三十”; }否则,如果(日期==31); DateName=“thirtyfirst”; 如果((月=1)和&(日期=22)){ 符号=“摩羯座”; }如果((month==1)|(month==2)&(date,java,javascript,string,Java,Javascript,String,您有一个分号,分号不应该在其中。代码的以下几行 String MonthName = "" ; String DateName = "" ; String sign = "" ; String horoscope = "" ; Scanner scan = new Scanner(System.in); System.out.println("Please enter your month of birth as an integer: "); int month= scan.ne

您有一个分号,分号不应该在其中。代码的以下几行

String MonthName = "" ; 

String DateName = "" ;

String sign = "" ;

String horoscope = "" ;

Scanner scan = new Scanner(System.in);

System.out.println("Please enter your month of birth as an integer: ");

int month= scan.nextInt();

System.out.println(" ");

System.out.println("Please enter your date of birth as an integer: ");

int date = scan.nextInt();

System.out.println(" ");


if (month == 1) {

    MonthName = "January";

} else if (month == 2) {

    MonthName = "February";

} else if (month == 3) {

    MonthName = "March";

} else if (month == 4) {

    MonthName = "April";

} else if (month == 5) {

    MonthName = "May" ;

} else if (month == 6) {

    MonthName = "June" ;

} else if (month == 7) {

    MonthName = "July" ;

} else if (month == 8) {

    MonthName = "August" ;

} else if (month == 9) {

    MonthName = "September" ;

} else if (month == 10) {

    MonthName = "October" ;

} else if (month == 11) {

    MonthName = "November" ;

} else if (month == 12) {

    MonthName = "December" ;
}


if (date == 1) {

    DateName = "first";

} else if (date == 2) {

    DateName = "second" ;

} else if (date == 3) {

    DateName = "third" ;

} else if (date == 4) {

    DateName = "fourth" ;

} else if (date == 5) {

    DateName = "fifth" ;

} else if (date == 6) {

    DateName = "sixth" ;

} else if (date == 7) {

    DateName = "seventh" ;

} else if (date == 8) {

    DateName = "eighth" ;

}  else if (date == 9) {

    DateName = "nineth" ;

}  else if (date == 10) {

    DateName = "tenth";

} else  if (date == 11) {

    DateName = "eleventh";

} else if (date == 12) {

    DateName = "twelfth";

} else  if (date == 13) {

    DateName = "thirteenth";

} else if (date == 14) {

    DateName = "fourteenth";

} else if (date == 15) {

    DateName = "fifteenth" ;

} else if (date == 16) {

    DateName = "sixteenth" ;

} else if (date == 17) {

    DateName = "seventeenth" ;

} else if (date == 18) {

    DateName = "eighteenth" ;

} else if (date == 19) {

    DateName = "nineteenth";

} else if (date == 20) {

    DateName = "twentieth";

} else if (date == 21) {

    DateName = "twentyfirst";

} else if (date == 22) {

    DateName = "twentysecond";

} else if (date == 23) {

    DateName = "twenty-third";

} else if (date == 24) {

    DateName = "twenty-fourth";

} else if (date == 25) {

    DateName = "twentyfifth";

} else if (date == 26) {

    DateName = "twentysixth";

} else if (date == 27) {

    DateName = "twentyseventh";

} else if (date == 28) {

    DateName = "twentyeight";

} else if (date == 29) {

    DateName = "twentynineth";

} else if (date == 30) {

    DateName = "thirtieth";

} else if (date == 31) ;

   DateName = "thirtyfirst" ;


if((month == 1) && (date <= 20) || (month == 12) && (date >= 22)) {

sign = "Capricorn";

} else if((month == 1) || (month == 2) && (date <= 19)) {

sign = "Aquarius";

} else if((month == 2) || (month == 3) && (date <= 20)) {

sign = "Pisces";

} else if((month == 3) || (month == 4) && (date <= 19)) {

sign = "Aries";

} else if((month == 4) || (month == 5) && (date <= 21)) {

sign = "Taurus";

} else if((month == 5) || (month == 6) && (date <= 21)) {

sign = "Gemini";

} else if((month == 6) || (month == 7) && (date <= 23)) {

sign = "Cancer";

} else if((month == 7) || (month == 8) && (date <= 23)) {

sign = "Leo";

} else if((month == 8) || (month == 9) && (date <= 23)) {

sign = "Virgo";

} else if((month == 9) || (month == 10) && (date <= 23)) {

sign = "Libra";

} else if((month == 10) || (month == 11) && (date <= 22)) {

sign = "Scorpio";

} else if(month == 12) {

sign = "Sagittarius";

}


if (sign.equals("Aries")) {

   horoscope= " You are the pioneer type and think most people are quick-tempered, impatient, and irritating.";

} else if (sign.equals("Leo")) {

    horoscope = "You consider yourself a born leader while others think you're the biggest bully out there. ";

} else if (sign.equals("Sagittarius")) {

    horoscope = "It's your time to be successful around the 19th!";

} else if (sign.equals("Taurus")) {

    horoscope = " Most people think you are stubborn and bullheaded. You are actually nothing but a communist.";

} else if (sign.equals("Virgo")) {

    horoscope = "You are logical, cold and unemotional, and hate disorder to an extreme level, like seriously.";

} else if (sign.equals("Capricorn")) {

    horoscope = "You are conservative and are afraid of taking risks, so you should just become a monk. ";

} else if (sign.equals("Gemini")) {

    horoscope = "You are a quick and intelligent thinkery Also, you are inclined to expect way too much for too little.";

} else if (sign.equals("Libra")) {

    horoscope = "You are the artistic type and have a difficult time with reality. Ouch, life must be hard for you."; 

} else if (sign.equals("Aquarius")) {

    horoscope = "You  are inclined to be progressive because you lie a great deal even though you make many mistakes."; 

} else if (sign.equals("Cancer")) {

    horoscope = "You are sympathetic and understanding to other peoples problems, yet you need to stop putting things off. ";

} else if (sign.equals("Scorpio")) {

    horoscope = "You are shrewd in business and cannot be trusted. You shall achieve the pinnacle of success because of your total lack of ethics";

} else if (sign.equals("Pisces")) {

    horoscope = "You have a vivid imagination and often think you are being followed by the FBI or CIA. Like, you need to wake up. ";

}


System.out.println("Your birthday is: " + MonthName + " " + DateName);

System.out.println(" ");

System.out.println("Your horoscope sign is: " + sign);

System.out.println(" ");

System.out.println("Horoscope: "+ horoscope);
System.out.println(" ");

    }

}
无条件地将
DateName
设置为
“thirtyfirst”
,而不管在前面的
if/else
测试链中发生了什么。将上述内容替换为:

} else if (date == 31) ;

DateName = "thirtyfirst" ;

顺便说一句:你应该学会使用数组。这将大大简化你的代码。

这不是一个真正的答案,但我还不能评论

使用日历(我自己通常使用GregorianCalendar)和应用格式可能会更好,这样你就可以整理代码。此外,如果你决定将来以不同的方式显示出生日期,那么重复工作就更少了


似乎您对编程有点陌生,因此您可能也会发现“case语句”很有用。您可能还能够更好地发现错误/缺少的块,就像您在这里发布的示例代码中所示。(其他两个答案已经提供了解决方案,因此我不再重复。)

哇……请仅包含与您的问题相关的代码,并查看常见问题解答中的代码格式指南:
} else if (date == 31) {
    DateName = "thirtyfirst" ;
}