新手求意见 定义的一学生类,并创建类的对象。

zhishiheng 2011-09-15 08:04:02
import java.util.*;
public class student {
String stnum;
String name;
String sex;
int age;
void getStnum()
{
System.out.println("请输入学号:");
Scanner a = new Scanner(System.in);
stnum = a.next();
};
void getName()
{
System.out.println("请输入学生姓名:");
Scanner a = new Scanner(System.in);
name = a.next();
}
void getSex()
{
System.out.println("请输入学生性别:");
Scanner a = new Scanner(System.in);
sex = a.next();
}
void getAge()
{
Scanner scanner=new Scanner(System.in);
System.out.println("输入学生年龄:");
age=scanner.nextInt();
}
void alterAge()
{
int b;
Scanner scanner=new Scanner(System.in);
System.out.println("输入你要改变的数值:");
b=scanner.nextInt();
age=b;
}
public static void main(String[] args) {
student A=new student();
student B=new student();
A.getStnum();
A.getSex();
A.getName();
A.getAge();
B.getStnum();
B.getSex();
B.getName();
B.getAge();
B.alterAge();
System.out.println("学号:"+A.stnum+"性别:"+A.sex+"姓名:"+A.name+"年龄:"+A.age+"学号:"+B.stnum+"性别:"+B.sex+"姓名:"+"姓名:"+B.name+"年龄:"+B.age);
}
}

我费解的是为什么输入的姓名,性别为中文,输出就出问题了?
...全文
217 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
baillluu 2011-09-15
  • 打赏
  • 举报
回复
问题到没看出什么来!
不过lz写代码很不规范,到是看出来来了,类名不以大写字目开头,不规范,如果是个JavaBean,那么因该写到应的get,set方法,而不是get来设置一个属性的值,不是么?
icemansuccess 2011-09-15
  • 打赏
  • 举报
回复
我把你的代码放到eclipse里面运行了,并没有问题.
郑宏辉 2011-09-15
  • 打赏
  • 举报
回复
System.in是一个InputStream,也就是字节流。in是System这个类的一个属性来着。中文是两个字节,再往里面读的时候,是把中文拆成两个字节读进去了,但是虚拟机却只是以字节输出,怎么知道你是要中文输出呢!
zhishiheng 2011-09-15
  • 打赏
  • 举报
回复
不能不承认 我跟兄台差距还是挺大滴![Quote=引用 1 楼 niuniu20008 的回复:]

用编译工具了吗?比如eclipse?
[/Quote]
paul-yanlx 2011-09-15
  • 打赏
  • 举报
回复
把错误信息贴出来吧!
Adamently 2011-09-15
  • 打赏
  • 举报
回复
貌似没看出有什么问题,可能是你输入的时候没有换行。
还有, 类名应该大写得哟!
niuniu20008 2011-09-15
  • 打赏
  • 举报
回复
用编译工具了吗?比如eclipse?

62,634

社区成员

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

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