import java.util.*;
import java.io.*;
class Student{
int id; //学号
String name; //姓名
String score[] = new String[4]; //四科成绩
float average; //平均分
float total; //总分
String subject[] = {"政治","数学","英语","专业课"}; //课程名
//int flag;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@我是分割线@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class StudentInfo2{
public static String s;
public static int _id = 0;
public static int i;
public static Student stu[] = new Student[100];
static int flag = 0;
public static void main(String args[]) throws Exception{
do{
int num;
System.out.println("**************************************");
System.out.println("* *");
System.out.println("* 学生成绩管理系统 *");
System.out.println("* *");
System.out.println("**************************************");
System.out.println("1.输入学生信息。");
System.out.println("2.查询学生信息。");
System.out.println("3.修改学生信息。");
System.out.println("4.退出。");
System.out.print("请选择(0-4):");
InputStreamReader iin = new InputStreamReader(System.in);
BufferedReader bin = new BufferedReader(iin);
num = Integer.parseInt(bin.readLine());
System.out.println(num);
switch(num){
case 1: setInfo();break;
case 2: showInfo();break;
case 3: modifyInfo();break;
case 4: System.exit(0);
}
}
while(flag == 1);
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@我也是分割线@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public static void setInfo() throws Exception{
//while(true){
//try{ //输入信息
InputStreamReader iin = new InputStreamReader(System.in);
BufferedReader bin = new BufferedReader(iin);
System.out.println("请输入编号:" + (int)(_id+1));
stu[_id].id = _id;
System.out.print("请输入姓名:");
s=bin.readLine();
stu[_id].name=s;
for(i = 0;i<4;i++){
System.out.println("请输入" + stu[_id].subject[i] + "成绩:");
stu[_id].score[i] = bin.readLine();
}
_id++;
System.out.print("是否继续输入?(y/n)");
while(true){
s=bin.readLine();
if(!s.equals("y") && !s.equals("n")){
System.out.print("有错,请重新输入");
}
else{
break;
}
}
if(s.equals("n"))
{
flag = 1;
}
//}
//catch(Exception e)
//{
//System.out.print("错误"); //}
//}
}
public static void showInfo() throws Exception{
}
public static void modifyInfo() throws Exception{ //修改信息
}
}
import java.io.*;
class Student{
int id; //学号
String name; //姓名
String score[] = new String[4]; //四科成绩
float average; //平均分
float total; //总分
String subject[] = {"政治","数学","英语","专业课"}; //课程名
//int flag;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@我是分割线@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class StudentInfo2{
public static String s;
public static int _id = 0;
public static int i;
public static Student stu[] = new Student[100];
static int flag = 0;
public static void main(String args[]) throws Exception{
do{
int num;
System.out.println("**************************************");
System.out.println("* *");
System.out.println("* 学生成绩管理系统 *");
System.out.println("* *");
System.out.println("**************************************");
System.out.println("1.输入学生信息。");
System.out.println("2.查询学生信息。");
System.out.println("3.修改学生信息。");
System.out.println("4.退出。");
System.out.print("请选择(0-4):");
InputStreamReader iin = new InputStreamReader(System.in);
BufferedReader bin = new BufferedReader(iin);
num = Integer.parseInt(bin.readLine());
System.out.println(num);
switch(num){
case 1: setInfo();break;
case 2: showInfo();break;
case 3: modifyInfo();break;
case 4: System.exit(0);
}
}
while(flag == 1);
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@我也是分割线@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public static void setInfo() throws Exception{
//while(true){
//try{ //输入信息
InputStreamReader iin = new InputStreamReader(System.in);
BufferedReader bin = new BufferedReader(iin);
System.out.println("请输入编号:" + (int)(_id+1));
stu[_id].id = _id;
System.out.print("请输入姓名:");
s=bin.readLine();
stu[_id].name=s;
for(i = 0;i<4;i++){
System.out.println("请输入" + stu[_id].subject[i] + "成绩:");
stu[_id].score[i] = bin.readLine();
}
_id++;
System.out.print("是否继续输入?(y/n)");
while(true){
s=bin.readLine();
if(!s.equals("y") && !s.equals("n")){
System.out.print("有错,请重新输入");
}
else{
break;
}
}
if(s.equals("n"))
{
flag = 1;
}
//}
//catch(Exception e)
//{
//System.out.print("错误"); //}
//}
}
public static void showInfo() throws Exception{
}
public static void modifyInfo() throws Exception{ //修改信息
}
}
这句有错误
只是分配了一百个格子的数组,数组中每个元素的值都还是null
你还要让每个stu[i] = new Student();
还有些细节自己想
判断一下stu[_id]是否为null,或者象2楼说的一样先对每个进行定义
if (stu[_id] == null)
stu[_id] = new student();