java程序,运行老出错。各位看看哪出错了

FFY_1208 2016-10-31 07:22:39
package javatext2016_11;

import java.util.*;
class Studen
{
private String name;
private String stu_num;
private int age;
private String yuxi;
void setname(String name)
{
this.name = name;
}
void setstu_num(String stu_num)
{
this.stu_num = stu_num;
}
void setage(int age)
{
this.age = age;
}
void setyuxi(String yuxi)
{
this.yuxi = yuxi;
}
String getname()
{
return name;
}
int getage()
{
return age;
}
String getstu_num()
{
return stu_num;
}
String getyuxi()
{
return yuxi;
}
}
public class Text1031_3 {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Map <String,Studen>students = new HashMap<String,Studen>();
Studen a;
char c;
System.out.println("请输入学生的人数:");
int number = input.nextInt();
for(int i=0;i<number;i++)
{
System.out.println("请输入学生的姓名,学号,院系,年龄!");
String name = input.nextLine();
String stu_num = input.nextLine();
String yuxi = input.nextLine();
int age = input.nextInt();
a = new Studen();
a.setage(age);
a.setname(name);
a.setstu_num(stu_num);
a.setyuxi(yuxi);
students.put(stu_num, a);
}
System.out.println("请输入需要查询的学生学号!");
String search = input.nextLine();
Studen person = students.get("001");
System.out.println("name is:"+person.getname()+"age is:"+person.getage()+"stu_num is: "+person.getstu_num()+" "+person.getyuxi());
input.close();
}

}
...全文
236 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
家里敷泥呀 2016-11-01
  • 打赏
  • 举报
回复
不看......
___d 2016-11-01
  • 打赏
  • 举报
回复
报错信息倒是贴。。。
月明星稀灬 2016-11-01
  • 打赏
  • 举报
回复
报错,错在哪? 报错信息是什么? 光有代码,猜不到问题。
  • 打赏
  • 举报
回复
class Studen { private String name; private String stu_num; private int age; private String yuxi; String getName() { return name; } void setName(String name) { this.name = name; } String getStu_num() { return stu_num; } void setStu_num(String stu_num) { this.stu_num = stu_num; } int getAge() { return age; } void setAge(int age) { this.age = age; } String getYuxi() { return yuxi; } void setYuxi(String yuxi) { this.yuxi = yuxi; } 测试代码: public class sa { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); Map<String, Studen> students = new HashMap<String, Studen>(); Studen a; char c; System.out.println("请输入学生的人数:"); int number = input.nextInt(); for (int i = 0; i < number; i++) { System.out.println("请输入学生的姓名,学号,院系,年龄!"); String name = input.nextLine(); String stu_num = input.nextLine(); String yuxi = input.nextLine(); int age = input.nextInt(); a = new Studen(); a.setAge(age); a.setName(name); a.setStu_num(stu_num); a.setYuxi(yuxi); students.put(stu_num, a); } System.out.println("请输入需要查询的学生学号!"); String search = input.nextLine(); Studen person = students.get("1"); System.out.println("name is:" + person.getName() + "age is:" + person.getAge() + "stu_num is: " + person.getStu_num() + " " + person.getYuxi()); input.close(); } }

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧