gpt4 book ai didi

java - 帮助!错误: The local variable transactionType may not have been initialized

转载 作者:太空宇宙 更新时间:2023-11-04 08:42:10 24 4
gpt4 key购买 nike

我明白了错误:局部变量 transactionType 可能尚未初始化

但问题是它是在我的 if 语句中初始化的!

if (transactionChar == 'w')
transactionType = "Withdrawal";

else if (transactionChar == 'd')
transactionType = "Deposit" ;

然后当我去打印出 transactionType 时,它​​不会让我这么做,因为它给了我这个错误! 我的声明声明看起来像这样。

String transactionType;
char transactionChar;

请帮忙。在过去的 4 个小时里我一直在试图弄清楚!

最佳答案

初始化变量:

String transactionType = "";
char transactionChar = '';

(不确定字符,因为我通常使用 C#)。

关于java - 帮助!错误: The local variable transactionType may not have been initialized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5070722/

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