gpt4 book ai didi

eclipse - 请在我的 Java 代码中解释这一行?

转载 作者:行者123 更新时间:2023-11-29 05:41:46 25 4
gpt4 key购买 nike

我刚刚开始学习 Java,直到学习了数组,我正在准备这个程序(来自一本书),用 '.' 替换空格 ' ' (点)我无法理解这一特定行(即使在我正在学习的书中也没有提到)。

请帮帮我。

class SpaceRemover{
public static void main(String[] args){
String mostFamous = "Hey there stackoverFLow ";
char [] mf1 = mostFamous.toCharArray();
for(int dex = 0; dex<mf1.length;dex++)
{
char current = mf1[dex]; // What is happening in this line ??
if (current != ' ') {
System.out.print(current);

}
else{
System.out.print('.');

}
}
System.out.println();


}
}

有人请解释“char current = mf1[dex];”中发生了什么

非常感谢您的宝贵时间。

最佳答案

您正在获取字符数组 mf1 中的第 dex 个字符/项(因此 mf1[dex])并将其存储到局部变量 current.

关于eclipse - 请在我的 Java 代码中解释这一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17267595/

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