java程序读取我的字符串输入作为变量

时间:2014-03-27 05:35:49

标签: java

有人可以帮助我吗?这只是一个测试,但是当我运行我的程序时,我得到一个找不到符号错误,它指出我输入的名称,认为它是一个变量

import java.util.*;
import java.io.*;
public class Employee{
    public String emp_name;
    public int emp_id;
    public double emp_salary;
    public int emp_phone;

    public Employee(String add_newName, int add_newID, double add_newSalary, int add_newPhone){
        emp_name = add_newName;
        emp_id = add_newID;
        emp_salary = add_newSalary;
        emp_phone = add_newPhone;
    }

    public Employee(int add_ID, int add_Phone){
        emp_name = "NULL";
        emp_id = add_ID;
        emp_salary = 0;
        emp_phone = add_Phone;
    }

    public double increaseSalary(double increase_amt){
        return emp_salary += increase_amt;
    }

    public String getName(){
        return emp_name;
    }

    public String toString(){
        return "Name of employee: " + emp_name + ",, " + "ID number of employee: " + emp_id + ",, " + "Employee salary: " + emp_salary + ",, " + "Employee phone: " + emp_phone;
    }

    public static void process(){
        Employee employee1 = new Employee(noel, 101, 5050.50, 1230987);
        Employee employee2 = new Employee(102, 5672389);
        System.out.println("Employee Information: " + employee1.toString());
    }

    public static void main(String args[]){
        process();
    }
}

错误是在进程方法中,你看到noel,java说找不到它的符号......求助?

3 个答案:

答案 0 :(得分:3)

noel更改为"noel"

Employee employee1 = new Employee("noel", 101, 5050.50, 1230987);

没有"" java会将其视为变量

答案 1 :(得分:2)

Java中String的语法是:

"Some String"

请注意双引号。要解决您的问题,您必须写"noel"

Employee employee1 = new Employee("noel", 101, 5050.50, 1230987);

答案 2 :(得分:1)

您通过传递noel创建员工

  Employee employee1 = new Employee(noel, 101, 5050.50, 1230987);

它应该是String as:

 Employee employee1 = new Employee("noel", 101, 5050.50, 1230987);