Java 请帮忙看一下?其中“output += count + "";”为什么提示“无法访问的语句”?

来源:百度知道 编辑:UC知道 时间:2024/06/17 03:15:37
import javax.swing.JOptionPane;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
public class Java_1 {

public static void main(String args[]) {
String output = "";
//*********Found********
for (int count = 1; count <= 10; count++) {
//*********Found********
if (count == 5) {
continue; // 当count为5时跳过循环中的剩余代码
output += count + "";
}
}
output += "\nUsed continue to skip printing 5";
JOptionPane.showMessageDialog(null, output);
System.exit(0);
}
}

因为你把这句放在了continue的后边了,一continue就会跳过本次循环,执行下次循环,所以你这句永远也不回执行,所以提示这般

output += count + "";

output是string的count是int的吧
应该
output += String.valueof(count) + "";

我的这句你稍微改改吧 大小写和括号(我用中文的括号)什么的

2楼回答正确

2楼正解,我就不废话了,一楼绝对不对