| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 683 人关注过本帖
标题:[求助]为何我编的程序只查找出第一个学生信息?
取消只看楼主 加入收藏
ss128
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-6-5
收藏
 问题点数:0 回复次数:2 
[求助]为何我编的程序只查找出第一个学生信息?

题目:
编写一个学生类,要求有学号、姓名、性别、班级字段。要求实现构造函数和默认构造函数,并实现show方法用来显示学生基本信息。创建一个学生类数组(长度为5),并在数组中存放在3个学生信息。从键盘输入学号,把相应的学生信息查找并显示出来。


txu6LW9A.txt (1.71 KB) [求助]为何我编的程序只查找出第一个学生信息?


[此贴子已经被作者于2006-6-5 22:17:20编辑过]



K1PIXTo3.txt (1.54 KB) 为何我编的程序只查找出第一个学生信息?

搜索更多相关主题的帖子: 学生 
2006-06-05 19:23
ss128
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-6-5
收藏
得分:0 

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class StudentTest {
public static void main(String[] args) {
int id = 0;
try {
System.out.print("Enter id: ");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

id = Integer.valueOf(br.readLine());
} catch(Exception e) {

}

StudentManager[] student = new StudentManager[5];

student[0] = new StudentManager(1,"a","W","001");
student[1] = new StudentManager(2,"b","M","003");
student[2] = new StudentManager(3,"c","W","001");

System.out.println(student[id-1].show());
}
}

class StudentManager {
private int id;

private String studentName,studentSex,studentClass;

StudentManager(int id,String studentName,String studentSex,String studentClass) {
this.id = id;
this.studentName = studentName;
this.studentSex = studentSex;
this.studentClass = studentClass;
}

StudentManager() {

}

String show() {
return id + " , " + studentName + " , " + studentSex + " , " + studentClass;
}
}


这个程序运行不得啊


2006-06-06 15:48
ss128
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-6-5
收藏
得分:0 

import java.util.*;
import java.io.*;
class Student
{
String name;
String num;
String sex;
String cla;
public Student(String name,String num,String sex,String cla)
{
this.name=name;
this.num=num;
this.sex=sex;
this.cla=cla;
}
public Student()
{
}
public String show()
{
return "name=" + name + " "+ "num=" + num + " " +"sex=" +
sex +" " + "cla=" +cla;
}
public String getNum()
{
return num;
}
}

class Collage extends Student
{
String department;
public Collage(String name,String num,String sex,String cla,
String department)
{
super(name,num,sex,cla);
this.department=department;
}
public String show()
{
return super.show()+"department=" + department;
}
}
public class StudentTest
{

public static void main(String s[])
{
String S=" ";
String sNum=" ";
Student e[]=new Student[3];
e[0]=new Student("李四","001","男","1班");
e[1]=new Student("张三","002","男","1班");
e[2]=new Student("李强","003","女","2班");
for (int i=0;i<e.length;i++)
{
String sBuf=e[i].show();
System.out.println(sBuf);
}
System.out.println("请输入学号:");
try
{
BufferedReader din=new BufferedReader(new InputStreamReader(System.in));
S=din.readLine();
}
catch (Exception b)
{
}
for(int i=0;i<e.length;i++)
{
sNum=e[i].getNum();
if((S.equals(sNum)))
{
System.out.println(e[i].show());
break;
}
else
{
System.out.println("对不起,你输入的学号不存在!");
break;
}
}
try
{
System.in.read();
}
catch (IOException c)
{
}
}
}


运行这个程序,如果输入学号002或003的话都显示输入的学号不存在,要怎么解决这个问题?

2006-06-06 16:02
快速回复:[求助]为何我编的程序只查找出第一个学生信息?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.094056 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved