packagesubject jesse; 
import java.io.*; 
  
public class stu 
{ public static int bianhao=0,f_bh; 
  public static int bh; 
  public static String s; 
public static class student 
{    
public int bianhao; 
public String name; 
  public String subject; 
  public String sex; 
}; 
public static student[] st=new student[100]; 
     
  
  
public static void main(String args[]) 
{    
for(int i=0;i<=99;i++) 
{ st[i]=new student(); 
st[i].bianhao=-1; 

System.out.print("*******************\n**欢迎使用学生信息管理系统**\n*******************\n"); 
first(); 
  xz();   
   
  

public static void xz() 

while(true) 

System.out.print("请输入:"); 
try 
{ BufferedReader Console=new BufferedReader(new InputStreamReader(System.in)); 
  
s=Console.readLine(); 
bh=Integer.parseInt(s); 
break; 

catch(Exception e) 

System.out.print("你输入的有误,请输入(1,2,3,4,5,0)其中人一个\n"); 


  
switch(bh) 

case 0:break; 
case 1:add();first();xz();break; 
case 2:del();first();xz();break; 
case 3:mod();first();xz();break; 
case 4:find();first();xz();break; 
case 5:showall();first();xz();break; 
  

  

  public static void first() 

      
System.out.print("1---增加\n"); 
System.out.print("2---删除\n"); 
System.out.print("3---修改\n"); 
System.out.print("4---查询\n"); 
System.out.print("5---显示\n"); 
System.out.print("0---退出\n"); 
  

public static void add() 
  

while(true) 
  

try{ 
BufferedReader Console=new BufferedReader(new InputStreamReader(System.in)); 
System.out.println("请输入编号:"+(int)(bianhao+1)); 
st[bianhao].bianhao=(int)(bianhao+1); 
System.out.print("请输入姓名:"); 
s=Console.readLine(); 
st[bianhao].name=s; 
System.out.print("请输入科目:"); 
st[bianhao].subject=Integer.parseInt(Console.readLine()); 
System.out.print("请输入性别:"); 
s=Console.readLine(); 
st[bianhao].sex=s; 
bianhao++; 
  System.out.print("是否继续输入?(y/n)"); 
while(true) 

s=Console.readLine(); 
if(!s.equals("y") && !s.equals("n")) 

System.out.print("有错,请重新输入"); 
  

else
{break; 


if(s.equals("n")) 

break; 


  catch(Exception e) 
  { 
  System.out.print("错误"); 
  
  } 


public static void del() 
{ try{ 
BufferedReader Console=new BufferedReader(new InputStreamReader(System.in)); 
System.out.print("请输入学生编号"); 
while(true) 

f_bh=Integer.parseInt(Console.readLine()); 
if (f_bh>=1 && f_bh<=100) 

if(show(f_bh-1)) 

System.out.print("确认删除?(y/n)"); 
while(true) 

s=Console.readLine(); 
if(!s.equals("y") && !s.equals("n")) 

System.out.print("有错,请重新输入"); 

else

break; 


if(s.equals("n")) 

  
break;   

else if(s.equals("y")) 

st[f_bh-1].bianhao=-1; 
st[f_bh-1].name=""; 
st[f_bh-1].subject=0; 
st[f_bh-1].sex=""; 
System.out.print("删除成功"); 
break; 

  
  

else
  
{break; 

  

else

System.out.print("你输入的编号不在1-100内,重输"); 


  

catch(Exception e) 

  
System.out.print("错误"); 
  } 

public static void mod() 
  { try{ 
System.out.print("请输入学生编号"); 
while(true) 
{BufferedReader Console=new BufferedReader(new InputStreamReader(System.in)); 
f_bh=Integer.parseInt(Console.readLine()); 
if (f_bh>=1 && f_bh<=100) 

if(show(f_bh-1)) 

System.out.print("确认修改?(y/n)"); 
while(true) 

s=Console.readLine(); 
if(!s.equals("y") && !s.equals("n")) 

System.out.print("有错,请重新输入"); 

  
if(s.equals("n")) 

  
  break; 

else if(s.equals("y")) 
{    
System.out.println("姓名当前值:"+st[f_bh-1].name+",更改为:(#表示不修改)"); 
      
s=Console.readLine(); 
if(!s.equals("#")) 
st[f_bh-1].name=s; 
System.out.println("科目当前值:"+st[f_bh-1].subject+",更改为:(#表示不修改)"); 
s=Console.readLine(); 
if(!s.equals("#")) 
st[f_bh-1].subject=Integer.parseInt(s); 
System.out.println("性别当前值:"+st[f_bh-1].sex+",更改为:(#表示不修改)"); 
s=Console.readLine(); 
if(!s.equals("#")) 
st[f_bh-1].sex=s; 
System.out.print("修改成功\n"); 
  
  break; 



break; 

else

System.out.print("你输入的编号不在1-100内,重输"); 



catch(Exception e) 

System.out.print("错误"); 


public static void find() 
  
{ try{ 
System.out.print("请输入学生编号"); 
while(true) 
{ BufferedReader Console=new BufferedReader(new InputStreamReader(System.in)); 
f_bh=Integer.parseInt(Console.readLine()); 
if (f_bh>=1 && f_bh<=100) 
{show(f_bh-1); 
break; 

else
{System.out.print("你输入的编号不在1-100内,重输"); 



catch(Exception e) 
{System.out.print("错误"); 


public static void showall() 
{ System.out.print("编号 姓名 年龄 性别\n"); 
for(int i=0;i<=99;i++) 
if (st[i].bianhao!=-1) 
{System.out.println(st[i].bianhao+" "+st[i].name+" "+st[i].subject+" "+st[i].sex+"\n"); 

  

public static boolean show(int a) 

if(st[a].bianhao!=-1) 

System.out.println("编号 姓名 年龄 性别\n"); 
System.out.println(st[a].bianhao+" "+st[a].name+" "+st[a].subject+" "+st[a].sex+"\n"); 
  return true; 

else
{System.out.print("无此记录或已被删除\n"); 
return false; 


  
}

解决方案 »

  1.   

    stu.java:1需要class、interface或enum
    packagesubject jesse;此为出现的一个错误
      

  2.   

    packagesubject jesse;
    这样命名包名,不对.要改一下:
    package   subject.jesse;
      

  3.   

      public String subject; 
    代码里这个属性都当int用, 所以把这个改一下:
      public  int  subject; 
      

  4.   

    public static class student 
    {    
    public int bianhao; 
    public String name; 
      public String subject; 
      public String sex; 
    };
    一个类不能修饰成静态的
    static关键字只能修饰成员变量和成员方法
      

  5.   

    import java.io.*;class student {
    public int bianhao;
    public String name;
    public int subject;
    public String sex;
    }public class Main {
    public static int bianhao = 0, f_bh;
    public static int bh;
    public static String s;
    public static student[] st = new student[100]; public static void main(String[] args) {
    for (int i = 0; i <= 99; i++) {
    st[i] = new student();
    st[i].bianhao = -1;
    }
    System.out.print("*******\n**欢迎使用学生信息管理系统**\n********\n");
    menu();
    } public static int choice() {
    while (true) {
    try {
    BufferedReader Console = new BufferedReader(
    new InputStreamReader(System.in)); s = Console.readLine();
    bh = Integer.parseInt(s);
    return bh;
    } catch (Exception e) {
    System.out.print("你输入的有误,请输入(1,2,3,4,5,0)其中人一个\n");
    }
    }
    } public static void menu() {
    int choiceResult;
    while (true) {
    System.out.print("1---增加\n");
    System.out.print("2---删除\n");
    System.out.print("3---修改\n");
    System.out.print("4---查询\n");
    System.out.print("5---显示\n");
    System.out.print("0---退出\n");
    System.out.print("请输入:");
    choiceResult = choice();
    if (choiceResult == 0) {
    break;
    }
    switch (choiceResult) {
    case 1: add(); break;
    case 2: del(); break;
    case 3: mod(); break;
    case 4: find(); break;
    case 5: showall(); break;
    }
    }
    } public static void add() {
    do {
    try {
    BufferedReader Console = new BufferedReader(
    new InputStreamReader(System.in));
    System.out.println("请输入编号:" + (int) (bianhao + 1));
    st[bianhao].bianhao = (int) (bianhao + 1);
    System.out.print("请输入姓名:");
    s = Console.readLine();
    st[bianhao].name = s;
    System.out.print("请输入科目:");
    st[bianhao].subject = Integer.parseInt(Console.readLine());
    System.out.print("请输入性别:");
    s = Console.readLine();
    st[bianhao].sex = s;
    bianhao++;
    System.out.print("是否继续输入?(y/n)");
    s = Console.readLine();
    while (!s.equals("y") && !s.equals("n")) {
    System.out.print("输入有误");
    s = Console.readLine();
    }
    } catch (Exception e) {
    System.out.print("错误");
    }
    } while (s.equals("n"));
    } public static void del() {
    try {
    BufferedReader Console = new BufferedReader(new InputStreamReader(
    System.in));
    System.out.print("请输入学生编号");
    while (true) {
    f_bh = Integer.parseInt(Console.readLine());
    if (f_bh >= 1 && f_bh <= 100) {
    if (show(f_bh - 1)) {
    System.out.print("确认删除?(y/n)");
    while (true) {
    s = Console.readLine();
    if (!s.equals("y") && !s.equals("n")) {
    System.out.print("有错,请重新输入");
    } else {
    break;
    }
    }
    if (s.equals("n")) {
    break;
    } else if (s.equals("y")) {
    st[f_bh - 1].bianhao = -1;
    st[f_bh - 1].name = "";
    st[f_bh - 1].subject = 0;
    st[f_bh - 1].sex = "";
    System.out.print("删除成功");
    break;
    }
    } else {
    break;
    }
    } else {
    System.out.print("你输入的编号不在1-100内,重输");
    }
    }
    } catch (Exception e) {
    System.out.print("错误");
    }
    } public static void mod() {
    try {
    System.out.print("请输入学生编号");
    while (true) {
    BufferedReader Console = new BufferedReader(
    new InputStreamReader (System.in));
    f_bh = Integer.parseInt(Console.readLine());
    if (f_bh >= 1 && f_bh <= 100) {
    if (show(f_bh - 1)) {
    System.out.print("确认修改?(y/n)");
    while (true) {
    s = Console.readLine();
    if (!s.equals("y") && !s.equals("n")) {
    System.out.print("有错,请重新输入");
    } if (s.equals("n")) { break;
    } else if (s.equals("y")) {
    System.out.println("姓名当前值:" + st[f_bh - 1].name
    + ",更改为:(#表示不修改)"); s = Console.readLine();
    if (!s.equals("#"))
    st[f_bh - 1].name = s;
    System.out.println("科目当前值:"
    + st[f_bh - 1].subject
    + ",更改为:(#表示不修改)");
    s = Console.readLine();
    if (!s.equals("#"))
    st[f_bh - 1].subject = Integer.parseInt(s);
    System.out.println("性别当前值:" + st[f_bh - 1].sex
    + ",更改为:(#表示不修改)");
    s = Console.readLine();
    if (!s.equals("#"))
    st[f_bh - 1].sex = s;
    System.out.print("修改成功\n"); break;
    }
    }
    }
    break;
    } else {
    System.out.print("你输入的编号不在1-100内,重输");
    }
    }
    } catch (Exception e) {
    System.out.print("错误");
    }
    } public static void find() {
    try {
    System.out.print("请输入学生编号");
    while (true) {
    BufferedReader Console = new BufferedReader(
    new InputStreamReader(System.in));
    f_bh = Integer.parseInt(Console.readLine());
    if (f_bh >= 1 && f_bh <= 100) {
    show(f_bh - 1);
    break;
    } else {
    System.out.print("你输入的编号不在1-100内,重输");
    }
    }
    } catch (Exception e) {
    System.out.print("错误");
    }
    } public static void showall() {
    System.out.print("编号 姓名 年龄 性别\n");
    for (int i = 0; i <= 99; i++) {
    if (st[i].bianhao != -1) {
    System.out.println(st[i].bianhao + " " + st[i].name + " "
    + st[i].subject + " " + st[i].sex + "\n");
    }
    }
    } public static boolean show(int a) {
    if (st[a].bianhao != -1) {
    System.out.println("编号 姓名 年龄 性别\n");
    System.out.println(st[a].bianhao + " " + st[a].name + " "
    + st[a].subject + " " + st[a].sex + "\n");
    return true;
    } else {
    System.out.print("无此记录或已被删除\n");
    return false;
    }
    }
    }
      

  6.   

    import java.io.*;class student {
    public int bianhao;
    public String name;
    public int subject;
    public String sex;
    }public class Main {
    public static int bianhao = 0, f_bh;
    public static int bh;
    public static String s;
    public static student[] st = new student[100]; public static void main(String[] args) {
    for (int i = 0; i <= 99; i++) {
    st[i] = new student();
    st[i].bianhao = -1;
    }
    System.out.print("*******\n**欢迎使用学生信息管理系统**\n********\n");
    menu();
    } public static int choice() {
    while (true) {
    try {
    BufferedReader Console = new BufferedReader(
    new InputStreamReader(System.in)); s = Console.readLine();
    bh = Integer.parseInt(s);
    return bh;
    } catch (Exception e) {
    System.out.print("你输入的有误,请输入(1,2,3,4,5,0)其中人一个\n");
    }
    }
    } public static void menu() {
    int choiceResult;
    while (true) {
    System.out.print("1---增加\n");
    System.out.print("2---删除\n");
    System.out.print("3---修改\n");
    System.out.print("4---查询\n");
    System.out.print("5---显示\n");
    System.out.print("0---退出\n");
    System.out.print("请输入:");
    choiceResult = choice();
    if (choiceResult == 0) {
    break;
    }
    switch (choiceResult) {
    case 1: add(); break;
    case 2: del(); break;
    case 3: mod(); break;
    case 4: find(); break;
    case 5: showall(); break;
    }
    }
    } public static void add() {
    do {
    try {
    BufferedReader Console = new BufferedReader(
    new InputStreamReader(System.in));
    System.out.println("请输入编号:" + (int) (bianhao + 1));
    st[bianhao].bianhao = (int) (bianhao + 1);
    System.out.print("请输入姓名:");
    s = Console.readLine();
    st[bianhao].name = s;
    System.out.print("请输入科目:");
    st[bianhao].subject = Integer.parseInt(Console.readLine());
    System.out.print("请输入性别:");
    s = Console.readLine();
    st[bianhao].sex = s;
    bianhao++;
    System.out.print("是否继续输入?(y/n)");
    s = Console.readLine();
    while (!s.equals("y") && !s.equals("n")) {
    System.out.print("输入有误");
    s = Console.readLine();
    }
    } catch (Exception e) {
    System.out.print("错误");
    }
    } while (s.equals("n"));
    } public static void del() {
    try {
    BufferedReader Console = new BufferedReader(new InputStreamReader(
    System.in));
    System.out.print("请输入学生编号");
    while (true) {
    f_bh = Integer.parseInt(Console.readLine());
    if (f_bh < 1 || f_bh >= 100) {
    System.out.print("你输入的编号不在1-100内,重输");
    continue;
    }
    if (!show(f_bh - 1)) {
    System.out.print("你输入的编号不存在,重输");
    continue;
    }
    System.out.print("确认删除?(y/n)");
    s = Console.readLine();
    while (!s.equals("y") && !s.equals("n")) {
    System.out.print("有错,请重新输入");
    s = Console.readLine();
    } if (s.equals("n")) {
    break;
    } else {
    st[f_bh - 1].bianhao = -1;
    st[f_bh - 1].name = "";
    st[f_bh - 1].subject = 0;
    st[f_bh - 1].sex = "";
    System.out.print("删除成功");
    break;
    }
    }
    } catch (Exception e) {
    System.out.print("错误");
    }
    } public static void mod() {
    try {
    System.out.print("请输入学生编号");
    while (true) {
    BufferedReader Console = new BufferedReader(
    new InputStreamReader(System.in));
    f_bh = Integer.parseInt(Console.readLine());
    if (f_bh < 1 || f_bh >= 100) {
    System.out.print("你输入的编号不在1-100内,重输");
    continue;
    }
    if (!show(f_bh - 1)) {
    System.out.print("你输入的编号不存在,重输");
    continue;
    }
    System.out.print("确认修改?(y/n)");
    s = Console.readLine();
    while (!s.equals("y") && !s.equals("n")) {
    System.out.print("有错,请重新输入");
    s = Console.readLine();
    }
    if (s.equals("n")) {
    break;
    } else {
    System.out.println("姓名当前值:" + st[f_bh - 1].name + ",更改为:(#表示不修改)");
    s = Console.readLine();
    if (!s.equals("#"))
    st[f_bh - 1].name = s;
    System.out.println("科目当前值:"+ st[f_bh - 1].subject + ",更改为:(#表示不修改)");
    s = Console.readLine();
    if (!s.equals("#"))
    st[f_bh - 1].subject = Integer.parseInt(s);
    System.out.println("性别当前值:" + st[f_bh - 1].sex + ",更改为:(#表示不修改)");
    s = Console.readLine();
    if (!s.equals("#"))
    st[f_bh - 1].sex = s;
    System.out.print("修改成功\n");
    break;
    }
    }
    } catch (Exception e) {
    System.out.print("错误");
    }
    } public static void find() {
    try {
    boolean done = false; 
    System.out.print("请输入学生编号");
    BufferedReader Console = new BufferedReader(new InputStreamReader(System.in));
    do{
    f_bh = Integer.parseInt(Console.readLine());
    if (f_bh >= 1 && f_bh <= 100) {
    show(f_bh - 1);
    done = true;
    } else {
    System.out.print("你输入的编号不在1-100内,重输");
    }
    }while(done);
    } catch (Exception e) {
    System.out.print("错误");
    }
    } public static void showall() {
    System.out.print("编号 姓名 年龄 性别\n");
    for (int i = 0; i <= 99; i++) {
    if (st[i].bianhao != -1) {
    System.out.println(st[i].bianhao + " " + st[i].name + " "
    + st[i].subject + " " + st[i].sex + "\n");
    }
    }
    } public static boolean show(int a) {
    if (st[a].bianhao != -1) {
    System.out.println("编号 姓名 年龄 性别\n");
    System.out.println(st[a].bianhao + " " + st[a].name + " "
    + st[a].subject + " " + st[a].sex + "\n");
    return true;
    }
    System.out.print("无此记录或已被删除\n");
    return false;
    }
    }