为什么这样写会报str cannot be resolved to a variable错


public void testSort3() {

List<Student> studentList = new ArrayList<Student>();//学生集合

List<String> studentIdList = new ArrayList<String>();//学生ID集合

//生成随机不重复的1000以内ID

Random rand = new Random();

for (int i = 0; i < 3; i++) {

//String str;

do {

String  str = new String(rand.nextInt(1000) + "");

} while (studentIdList.contains(str));

studentIdList.add(str);

}

}


codeboy__
浏览 4389回答 1
1回答

慕粉4075985

str是局部变量,你要把它写到外面去
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java