gpt4 book ai didi

Java: toString 错误 "error: incompatible types: int cannot be converted to String"

转载 作者:行者123 更新时间:2023-11-29 09:52:34 24 4
gpt4 key购买 nike

<分区>

我的toString 只需要一个快速的帮助。这涉及到打牌。

public class Card
{
//Data
private int rank;
private char rank2;
private char suit;

//more codes (constructor etc.)

//toString
public String toString ( )
{
if (rank == 11)
rank2 = 'J';
else if (rank == 12)
rank2 = 'Q';
else if (rank == 13)
rank2 = 'K';
else if (rank == 14)
rank2 = 'A';
else
return rank2 + suit; // <----error here.
}

我想弄清楚如何返回等级和西装。例如,如果有人输入等级 11 和花色“S”,那么我应该返回一个 JS。但是,我遇到了一个错误:

"error: incompatible types: int cannot be converted to String"

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