java新人问题

qq_33689013 2016-03-22 02:58:49
import java.util.*;
class people{
String name;
int age;
String sex;
}
class message{

void input(people a){
Scanner reader=new Scanner(System.in);
String a.name=reader.next();

int a.age=reader.nextInt();
while (a.age<0){
System.out.println("错误输入,重新输入!");
a.age=reader.nextInt();
}
String a.sex=reader.next();
}
void output(people a){
System.out.println("姓名:"+a.name);
System.out.println("年龄:"+a.age);
System.out.println("性别:"+a.sex);

}

}
public class lianxi1{
public static void main(String args[]){
a=new people();
b=new people();
zs=new message();
ls=new message();
zs.input(a);
ls.input(b);
zs.output(a);
ls.output(b);

}

}
报错总说少了分号为什么
...全文
102 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Spinach007 2016-03-22
  • 打赏
  • 举报
回复
错误太多, 基础不好。
threedong 2016-03-22
  • 打赏
  • 举报
回复
我把你的代码放在eclipse中, a=new people(); b=new people(); zs=new message(); ls=new message(); 这是错的。 应该这样吧? people a=new people(); people b=new people(); message zs=new message(); message ls=new message(); 接受的类型没有声明。 你的类名写的也不规范,类名首字母要大写
心随自在飞 2016-03-22
  • 打赏
  • 举报
回复
String a.name=reader.next(); 你有一个入参 people a 这里不用给String int a.age 这里int也不要 String int 等用于声明变量。 这里的a 是people 类型的,里面的字段已经在people类中声明过了。 而且多熟悉一下,变量命名规则。
qq_33689013 2016-03-22
  • 打赏
  • 举报
回复
引用 1 楼 xiesq5112 的回复:
用的什么开发工具。 一般都是提示错误在哪个位置啊!
请问我这么写哪里不对用的是intellij IDEA
心随自在飞 2016-03-22
  • 打赏
  • 举报
回复
用的什么开发工具。 一般都是提示错误在哪个位置啊!

23,404

社区成员

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

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