好几个 main函数 报错
- Syntax error on tokens, delete these tokens
- Syntax error on token "void", @ expected
- Syntax error on token "]", invalid (main函数下面创建em对象时候报错 Syntax error on token ")", { expected after this tokenif 报错 Syntax error on token(s), misplaced construct(s)
else if报错Syntax error on token "else", { expected
- Syntax error on tokens, delete these tokens
- Syntax error on token "void", @ expected
- Syntax error on token "]", invalid (main函数下面创建em对象时候报错 Syntax error on token ")", { expected after this tokenif 报错 Syntax error on token(s), misplaced construct(s)
else if报错Syntax error on token "else", { expected
Emp emp=new Emp(empNo,name,float sal)
em.addEmp(emp);
sal 这个变量怎么回事?
this.name = name;
this.EmpNo = empNo;
this.sal = salary;
}
构造函数?void?
这个void打错了 我删掉了 不过还是主函数报错
这个void打错了 我删掉了 不过还是主函数报错package com.test;import java.io.BufferedReader;
import java.io.InputStreamReader;public class TestEmpM {
public static void main(String[] args) throws Exception {
EmpManage em = new EmpManage();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 此处不可这么写,死循环....
// while (true) {
// System.out.println("please choose your option:");
// System.out.println("输入1代表你想增加新成员:");
// System.out.println("2 代表你想查询成员信息");
// System.out.println("3 代表你想更新成员薪水");
// System.out.println("4 代表你想删除某一成员");
// }
String operType = br.readLine();
if (operType.equals("1")) {
System.out.println("plz enter the name:");
String name = br.readLine();
System.out.println("plz enter the Nummber:");
String empNo = br.readLine();
System.out.println("plz enter the salary:");
float sal = Float.parseFloat(br.readLine());
Emp emp = new Emp(empNo, name, sal);
em.addEmp(emp);
System.out.println("success!");
em.showInfo(empNo);
} else if (operType.equals("2")) {
System.out.println("plz enter the Nummber:");
em.showInfo(br.readLine());
} else if (operType.equals("3")) {
System.out.println("plz enter the Nummber:");
String empNo = br.readLine();
System.out.println("plz enter the new salary:");
float sal = Float.parseFloat(br.readLine());
em.updateSal(empNo, sal);
} else if (operType.equals("4")) {
System.out.println("plz enter the Nummber:");
String EmpNo = br.readLine();
em.delEmp(EmpNo);
} else if (operType.equals("5")) {
System.exit(0);
}
//
}
}
请注意JAVA区分大小写的,还有一处死循环!
这个void打错了 我删掉了 不过还是主函数报错package com.test;import java.io.BufferedReader;
import java.io.InputStreamReader;public class TestEmpM {
public static void main(String[] args) throws Exception {
EmpManage em = new EmpManage();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 此处不可这么写,死循环....
// while (true) {
// System.out.println("please choose your option:");
// System.out.println("输入1代表你想增加新成员:");
// System.out.println("2 代表你想查询成员信息");
// System.out.println("3 代表你想更新成员薪水");
// System.out.println("4 代表你想删除某一成员");
// }
String operType = br.readLine();
if (operType.equals("1")) {
System.out.println("plz enter the name:");
String name = br.readLine();
System.out.println("plz enter the Nummber:");
String empNo = br.readLine();
System.out.println("plz enter the salary:");
float sal = Float.parseFloat(br.readLine());
Emp emp = new Emp(empNo, name, sal);
em.addEmp(emp);
System.out.println("success!");
em.showInfo(empNo);
} else if (operType.equals("2")) {
System.out.println("plz enter the Nummber:");
em.showInfo(br.readLine());
} else if (operType.equals("3")) {
System.out.println("plz enter the Nummber:");
String empNo = br.readLine();
System.out.println("plz enter the new salary:");
float sal = Float.parseFloat(br.readLine());
em.updateSal(empNo, sal);
} else if (operType.equals("4")) {
System.out.println("plz enter the Nummber:");
String EmpNo = br.readLine();
em.delEmp(EmpNo);
} else if (operType.equals("5")) {
System.exit(0);
}
//
}
}
请注意JAVA区分大小写的,还有一处死循环!谢谢 我修改了一下 写成这样:
public static void main(String[] args)
{ EmpManage em=new EmpManage();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{System.out.println("please choose your option:");
System.out.println("1 means you wanna add a employee:");
System.out.println("2 means you wanna get an employee's information");
System.out.println("3 means you wanna update an employee");
System.out.println("4 means you wanna delete an employee's information");
String operType=br.readline();
if(operType.equals("1"))
{
System.out.println("plz enter the name:");
String name=br.readLine();
System.out.println("plz enter the Nummber:");
String empNo=br.readLine();
System.out.println("plz enter the salary:");
float sal=Float.parseFloat(br.readLine());
Emp emp=new Emp(name,empNo,sal);
em.addEmp(emp);
System.out.println("success!");
em.showInfo(empNo);
}
else if(operType.equals("2"))
{System.out.println("plz enter the Nummber:");
em.showInfo(br.readline());
}
else if(operType.equals("3"))
{System.out.println("plz enter the Nummber:");
String empNo=br.readline();
System.out.println("plz enter the new salary:");
float sal=Float.parseFloat(br.readline());
em.update(empNo,sal);
}
else if(operType.equals("4"))
{System.out.println("plz enter the Nummber:");
String EmpNo=br.readline();
em.delEmp(EmpNo);
}
else if(operType.equals("5"))
{System.exit(0);}
}
}
这样就可以通过输入5来停止循环 but。。 还是有错
这个void打错了 我删掉了 不过还是主函数报错package com.test;import java.io.BufferedReader;
import java.io.InputStreamReader;public class TestEmpM {
public static void main(String[] args) throws Exception {
EmpManage em = new EmpManage();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 此处不可这么写,死循环....
// while (true) {
// System.out.println("please choose your option:");
// System.out.println("输入1代表你想增加新成员:");
// System.out.println("2 代表你想查询成员信息");
// System.out.println("3 代表你想更新成员薪水");
// System.out.println("4 代表你想删除某一成员");
// }
String operType = br.readLine();
if (operType.equals("1")) {
System.out.println("plz enter the name:");
String name = br.readLine();
System.out.println("plz enter the Nummber:");
String empNo = br.readLine();
System.out.println("plz enter the salary:");
float sal = Float.parseFloat(br.readLine());
Emp emp = new Emp(empNo, name, sal);
em.addEmp(emp);
System.out.println("success!");
em.showInfo(empNo);
} else if (operType.equals("2")) {
System.out.println("plz enter the Nummber:");
em.showInfo(br.readLine());
} else if (operType.equals("3")) {
System.out.println("plz enter the Nummber:");
String empNo = br.readLine();
System.out.println("plz enter the new salary:");
float sal = Float.parseFloat(br.readLine());
em.updateSal(empNo, sal);
} else if (operType.equals("4")) {
System.out.println("plz enter the Nummber:");
String EmpNo = br.readLine();
em.delEmp(EmpNo);
} else if (operType.equals("5")) {
System.exit(0);
}
//
}
}
请注意JAVA区分大小写的,还有一处死循环!谢谢 我修改了一下 写成这样:
public static void main(String[] args)
{ EmpManage em=new EmpManage();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{System.out.println("please choose your option:");
System.out.println("1 means you wanna add a employee:");
System.out.println("2 means you wanna get an employee's information");
System.out.println("3 means you wanna update an employee");
System.out.println("4 means you wanna delete an employee's information");
String operType=br.readline();
if(operType.equals("1"))
{
System.out.println("plz enter the name:");
String name=br.readLine();
System.out.println("plz enter the Nummber:");
String empNo=br.readLine();
System.out.println("plz enter the salary:");
float sal=Float.parseFloat(br.readLine());
Emp emp=new Emp(name,empNo,sal);
em.addEmp(emp);
System.out.println("success!");
em.showInfo(empNo);
}
else if(operType.equals("2"))
{System.out.println("plz enter the Nummber:");
em.showInfo(br.readline());
}
else if(operType.equals("3"))
{System.out.println("plz enter the Nummber:");
String empNo=br.readline();
System.out.println("plz enter the new salary:");
float sal=Float.parseFloat(br.readline());
em.update(empNo,sal);
}
else if(operType.equals("4"))
{System.out.println("plz enter the Nummber:");
String EmpNo=br.readline();
em.delEmp(EmpNo);
}
else if(operType.equals("5"))
{System.exit(0);}
}
}
这样就可以通过输入5来停止循环 but。。 还是有错while之后的代码是不可到达的代码....把你现在的代码(main)贴出来
应该为:
br.readLine();java区分大写,还有你的update,你定义的是update***
谢谢! readline这个还真不知道 改过来了 不过主函数报错依旧是
Multiple ers at this line
- Syntax error on token "]", invalid (
- Syntax error, insert ")" to complete
SingleMemberAnnotation
- Syntax error, insert "]" to complete ArrayAccess
- Syntax error, insert "enum Identifier" to complete
public static void main(String[] args) throws IOException { 需要抛出异常...,看你的报错应该是缺少“(”或者“)“,仔细看一下吧
public static void main(String[] args) throws IOException {
EmpManage em = new EmpManage();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("please choose your option:");
System.out.println("1 means you wanna add a employee:");
System.out
.println("2 means you wanna get an employee's information");
System.out.println("3 means you wanna update an employee");
System.out
.println("4 means you wanna delete an employee's information");
String operType = br.readLine();
if (operType.equals("1")) {
System.out.println("plz enter the name:");
String name = br.readLine();
System.out.println("plz enter the Nummber:");
String empNo = br.readLine();
System.out.println("plz enter the salary:");
float sal = Float.parseFloat(br.readLine());
Emp emp = new Emp(name, empNo, sal);
em.addEmp(emp);
System.out.println("success!");
em.showInfo(empNo);
} else if (operType.equals("2")) {
System.out.println("plz enter the Nummber:");
em.showInfo(br.readLine());
} else if (operType.equals("3")) {
System.out.println("plz enter the Nummber:");
String empNo = br.readLine();
System.out.println("plz enter the new salary:");
float sal = Float.parseFloat(br.readLine());
em.updateSal(empNo, sal);
} else if (operType.equals("4")) {
System.out.println("plz enter the Nummber:");
String EmpNo = br.readLine();
em.delEmp(EmpNo);
} else if (operType.equals("5")) {
System.exit(0);
}
}
}
运行结果:
==========================================================
please choose your option:
1 means you wanna add a employee:
2 means you wanna get an employee's information
3 means you wanna update an employee
4 means you wanna delete an employee's information
1
plz enter the name:
LISI
plz enter the Nummber:
110
plz enter the salary:
2310.23
success!
his information is:LISI 110 2310.23
please choose your option:
1 means you wanna add a employee:
2 means you wanna get an employee's information
3 means you wanna update an employee
4 means you wanna delete an employee's information可以结贴了
import java.io.*;
public class Emp {
private String name;
private String EmpNo;
private float sal;
public Emp(String name,String empNo,float salary) {
this.name=name;
this.EmpNo=empNo;
this.sal=salary;
}
public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
public void setEmpNo(String empNo) {
this.EmpNo=empNo;
}
public String getEmpNo() {
return EmpNo;
}
public void setSal(float sal) {
this.sal=sal;
}
public float getSal() {
return sal;
}
public static void main(String[] args) throws Exception {
EmpManage em = new EmpManage();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true) {
System.out.println("please choose your option:");
System.out.println("输入1代表你想增加新成员:");
System.out.println("2 代表你想查询成员信息");
System.out.println("3 代表你想更新成员薪水");
System.out.println("4 代表你想删除某一成员"); String operType = br.readLine(); if (operType.equals("1")) {
System.out.println("plz enter the name:");
String name=br.readLine();
System.out.println("plz enter the Nummber:");
String empNo=br.readLine();
System.out.println("plz enter the salary:");
float sal=Float.parseFloat(br.readLine());
Emp emp = new Emp(empNo, name, sal);
em.addEmp(emp);
System.out.println("success!");
em.showInfo(empNo);
}
else if(operType.equals("2")) {
System.out.println("plz enter the Nummber:");
em.showInfo(br.readLine());
}
else if(operType.equals("3")) {
System.out.println("plz enter the Nummber:");
String empNo=br.readLine();
System.out.println("plz enter the new salary:");
float sal=Float.parseFloat(br.readLine());
em.updateSal(empNo,sal);//原来是em.update 不知道改的对不对
}
else if(operType.equals("4")) {
System.out.println("plz enter the Nummber:");
String EmpNo=br.readLine();
em.delEmp(EmpNo);
}
else if(operType.equals("5")) {
System.exit(0);
}
}
}
}class EmpManage {
private ArrayList a1 = null;
public EmpManage() {
a1 = new ArrayList();
}
//加入员工
public void addEmp(Emp emp) {
a1.add(emp);
}
//显示信息
public void showInfo(String empNo) {
//取出对象
for(int i=0;i<a1.size();i++) {
Emp emp=(Emp)a1.get(i);
//比较编号
if (emp.getEmpNo().equals(empNo)) {
System.out.println("his information is:"+emp.getName()+" "+emp.getEmpNo()+" "+emp.getSal());
}
}
} //修改薪水
public void updateSal(String empNo, float newSal) {
for (int i = 0; i < a1.size(); i++) {
Emp emp=(Emp)a1.get(i);
if (emp.getEmpNo().equals(empNo)) {
emp.setSal(newSal);
}
}
}
//删除员工
public void delEmp(String EmpNo) {
for (int i = 0; i < a1.size(); i++) {
Emp emp=(Emp)a1.get(i);
if(emp.getEmpNo().equals(EmpNo)) {
a1.remove(i);
}
}
}
}
上面的完美运行 结贴吧 此楼40 不谢下面是结果
please choose your option:
输入1代表你想增加新成员:
2 代表你想查询成员信息
3 代表你想更新成员薪水
4 代表你想删除某一成员
1
plz enter the name:
n
plz enter the Nummber:
123
plz enter the salary:
456
success!
please choose your option:
输入1代表你想增加新成员:
2 代表你想查询成员信息
3 代表你想更新成员薪水
4 代表你想删除某一成员
2
plz enter the Nummber:
1
please choose your option:
输入1代表你想增加新成员:
2 代表你想查询成员信息
3 代表你想更新成员薪水
4 代表你想删除某一成员
1
plz enter the name:
name
plz enter the Nummber:
44546
plz enter the salary:
123
success!
please choose your option:
输入1代表你想增加新成员:
2 代表你想查询成员信息
3 代表你想更新成员薪水
4 代表你想删除某一成员
1
plz enter the name:
44546
plz enter the Nummber:
123
plz enter the salary:
1536
success!
please choose your option:
输入1代表你想增加新成员:
2 代表你想查询成员信息
3 代表你想更新成员薪水
4 代表你想删除某一成员
2
plz enter the Nummber:
44546
his information is:123 44546 1536.0
please choose your option:
输入1代表你想增加新成员:
2 代表你想查询成员信息
3 代表你想更新成员薪水
4 代表你想删除某一成员