gpt4 book ai didi

java - 错误消息 - java :24: Incompatible types

转载 作者:行者123 更新时间:2023-12-01 23:23:28 25 4
gpt4 key购买 nike

每次尝试编译程序时,我都会收到此错误消息:

SeasonTest.java:24: incompatible types
found : java.lang.String
required: int
int date = ("" + mo + day);
^
1 error

我正在尝试连接两个整数以在字符串返回方法中形成另一个整数变量:

static String season (int month, int day)
{
int date = ("" + month + day);

String season;

if (date >= 316 && date <= 615)
{
season = "spring";
return season;
}

我已经尝试过它,但我根本不明白问题出在哪里。

最佳答案

这个初始代码

int date = ("" + month + day); // Yields a string.

应该是这样的。

Calendar c = Calendar.getInstance(); // get a calendar instance.
int date = day;
for (int i = 0; i < month; i++) {
c.set(Calendar.MONTH, i); // set the month.
date += c.getActualMaximum(Calendar.DAY_OF_MONTH); //how many days are in that month?
}

关于java - 错误消息 - java :24: Incompatible types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20344347/

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