java数组 规定数量,根据其数量Java数组输入学生姓名 (Java array to input student names according to their number)...

作者求助于创建一个程序,要求教授输入班级学生数量并依次输入姓名。原始代码存在错误,包括输入验证和数组初始化。编辑后的代码解决了部分问题,但仍有学生名跳过的问题。博主寻求帮助解决代码中关于数组分配和用户输入处理的困惑。
摘要由CSDN通过智能技术生成

2014-04-19 20:21:41

0

I need to create an array that prompts a professor to input how many students are in their class. Then prompts them to input their names until the number of students is met. What I have is clearly wrong but I was hoping for some insight.

System.out.println("Please enter the number of students in the class: ");

int numberOfStudents = console.nextInt();

String [] studentName = new String [numberOfStudents];

for (int i=0; i

{

System.out.println("Enter the name of student " + (i+1) + " in your class. ");

studentName[i] = console.nextLine();

System.out.println("Student name entered: " + studentName[i]);

}

EDIT: I changed the code a bit, mainly the array. With the for loop I am intending to simply have it go through each number and assign a student name to it. But with the last line of code it gives me an error saying its a confusing indentation.

EDIT 2: After proofreading my question and the code myself I've noticed very basic mistakes and have dealt with them, but one last question. Right now while the code works, when it asks for me to input the name, it skips student 1, leaves it blank then moves onto student 2. As shown in this screenshot http://puu.sh/8fl8e.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值