当前位置: 代码迷 >> J2SE >> 啊请问关于 不可达代码
  详细解决方案

啊请问关于 不可达代码

热度:110   发布时间:2016-04-24 12:32:41.0
高手进啊!!!请教关于 不可达代码
输入教师信息,开始到了最后 System.out.println("论文大于20篇的教师信息如下:"); 这句话就成了 代码不可达 请教哪里出了问题???



package xs;

import java.util.Scanner;
class TeacherTest {
public static void main(String[] args) {
Teacher[] teachers = new Teacher[1000];
TeacherManager tech = new TeacherManager();
Scanner s = new Scanner(System.in);
System.out.println("请添加教师信息:");
int teacherId;
String teacherName;
int teacherDiscourse;
int i,n;
Teacher teacher; 
String q;
for(i=0; ;i++) {
System.out.println("教师编号:");
teacherId = s.nextInt();
System.out.println("教师姓名:");
teacherName = s.next();
System.out.println("教师论文数:");
teacherDiscourse = s.nextInt();
System.out.println("添加成功!");
teacher = new Teacher(teacherId,teacherName,teacherDiscourse);
tech.addTeacher(teacher, i);
System.out.println("退出请按q,继续请按任意键:");
q = s.next();
if (q.equals("q") == true || q.equals("Q") == true)
break;
}
System.out.println("您输入的信息如下:");
teachers = tech.getTeachers();
System.out.println("编号" + "\t" + "姓名" + "\t" + "论文数");
for(i=0; i<n ; i++) 
System.out.println(teachers[i].toTString());

System.out.println("论文大于20篇的教师信息如下:");
//teacher = tech.searchTeacherDiscourse(teacherId, count);

}
}



------解决方案--------------------
调试下 看是否运到到那里
------解决方案--------------------

少了一个括号。楼主,你发现了吗
Java code
import java.util.Scanner;public class TeacherTest {    public static void main(String[] args) {    TeacherManager teacherManager = new TeacherManager();    Scanner scanner = new Scanner(System.in);    System.out.println("请添加教师信息:");    int teacherId;    String teacherName;    int teacherDiscourse;    int i, n = 1000;//最多只能存放1000个老师    Teacher teacher;    String q;    for (i = 0; i < n; i++) {        System.out.println("教师编号:");        teacherId = scanner.nextInt();        System.out.println("教师姓名:");        teacherName = scanner.next();        System.out.println("教师论文数:");        teacherDiscourse = scanner.nextInt();        System.out.println("添加成功!");        teacher = new Teacher(teacherId, teacherName, teacherDiscourse);        teacherManager.addTeacher(teacher, i);        System.out.println("退出请按q,继续请按任意键:");        q = scanner.next();        if (q.equals("q") == true || q.equals("Q") == true)        break;    }    n = i;//保存最后一位老师的下标    System.out.println("您输入的信息如下:");    Teacher[] teachers = teacherManager.getTeachers();    System.out.println("编号" + "\t" + "姓名" + "\t" + "论文数");    for (i = 0; i < n; i++)        System.out.println(teachers[i]);    System.out.println("论文大于20篇的教师信息如下:");    for (i = 0; i < n; i++)        if (teachers[i].teacherDiscourse > 20)        System.out.println(teachers[i]);    }}class TeacherManager {    Teacher[] teachers = new Teacher[1000];    public void addTeacher(Teacher teacher, int i) {    teachers[i] = teacher;    }    public Teacher[] getTeachers() {    return teachers;    }}class Teacher {    int teacherId;    String teacherName;    int teacherDiscourse;    public Teacher(int teacherId, String teacherName, int teacherDiscourse) {    super();    this.teacherId = teacherId;    this.teacherName = teacherName;    this.teacherDiscourse = teacherDiscourse;    }    public String toString() {    return teacherId + " " + teacherName + " " + teacherDiscourse;    }}
  相关解决方案