gpt4 book ai didi

java - BlueJ 字符串条件错误

转载 作者:行者123 更新时间:2023-12-01 13:14:36 27 4
gpt4 key购买 nike

我的 BlueJ 在条件语句 if 中运行了错误的行。我的程序是:

import java.io.*;
public class version_check
{
public static void main(String args[])throws IOException
{
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your BlueJ version");
String version=read.readLine();
if(version!="3.1.1")
System.out.println("You need to upgrade your BlueJ version");
else
System.out.println("You have the latest BlueJ version");
}
}

输出屏幕:

Enter your BlueJ version
3.1.1
You need to upgrade your BlueJ version

我犯了什么错误?

最佳答案

使用 .equals 比较字符串。

if(version!="3.1.1")   
System.out.println("You need to upgrade your BlueJ version");

if(!(version.equals("3.1.1")))   
System.out.println("You need to upgrade your BlueJ version");

关于java - BlueJ 字符串条件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22573095/

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