为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

codeboy__ 2017-04-10 18:01:22
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); } }
查看完整描述

1 回答

已采纳
?
慕粉4075985

TA贡献104条经验 获得超33个赞

str是局部变量,你要把它写到外面去

查看完整回答
反对 回复 2017-04-10
  • 1 回答
  • 0 关注
  • 4384 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信