import java.util.*;
import javax.swing.*; public class ArraylistTest
 {
  public static void main(String[] args)
  {
  ArrayList staff=new ArrayList();
  do
  {
  String name=JOptionPane.showInputDialog
  ("Please input your name:");
 
  String input=JOptionPane.showInputDialog
  ("Please inout your salary:");
  int salary=Integer.parseInt(input);
 
  input=JOptionPane.showInputDialog
  ("Please input your year:");
  int year=Integer.parseInt(input);
 
  input=JOptionPane.showInputDialog
  ("Please input your mouth:");
  int mouth=Integer.parseInt(input);
 
  input=JOptionPane.showInputDialog
  ("Please input your day:");
  int day=Integer.parseInt(input);
 
  staff.add(new Employee(name,salary,year,mouth,day));
 
  input=JOptionPane.showInputDialog
  ("Ready:?(Y/N)");
  input=input.toUpperCase();
  }
      while (input.equals("N"));
      
      System.exit(0);
 
 
  for(int i=0;i<staff.size();i++)
  {
  Employee e=(Employee)staff.get(i);
  System.out.println
  ("name="+e.getName()+",salary"+e.getSalary()
  +",hireDay"+e.getHireDay());
  }
 
 
  }
 }  
这段程序为什么错在这里呢?我不明白,谢谢!  
symbol  : variable input 
location: class ArraylistTest
                while (input.equals("N"));
                       ^
1 error

解决方案 »

  1.   

    你的input根本就没有定义过呀~~~
    input是什么类型的,值为多少,在程序里根本就没有说明,所以就出错了~~~
      

  2.   

    我定义拉阿?
    String input=JOptionPane.showInputDialog
      

  3.   

    public class ArraylistTest
     {
      public static void main(String[] args)
      {
      ArrayList staff=new ArrayList();
                      String name = "";
                      String input = "";
      do
      {
      name=JOptionPane.showInputDialog
      ("Please input your name:");
     
      input=JOptionPane.showInputDialog
      ("Please inout your salary:");
      int salary=Integer.parseInt(input);
     
      input=JOptionPane.showInputDialog
      ("Please input your year:");
      int year=Integer.parseInt(input);
     
      input=JOptionPane.showInputDialog
      ("Please input your mouth:");
      int mouth=Integer.parseInt(input);
     
      input=JOptionPane.showInputDialog
      ("Please input your day:");
      int day=Integer.parseInt(input);
     
      staff.add(new Employee(name,salary,year,mouth,day));
     
      input=JOptionPane.showInputDialog
      ("Ready:?(Y/N)");
      input=input.toUpperCase();
      }
          while (input.equals("N"));
          
          System.exit(0);
     
     
      for(int i=0;i<staff.size();i++)
      {
      Employee e=(Employee)staff.get(i);
      System.out.println
      ("name="+e.getName()+",salary"+e.getSalary()
      +",hireDay"+e.getHireDay());
      }
     
     
      }
     }  这样,把变量声明在 do-while 的外边
      

  4.   

    循环内的定义对while (input.equals("N"));无效。
      

  5.   

    你在do中声明的变量是没发在while里使用的
    因为它的生存期只在do执行的时候~~~
      

  6.   

    看看作用域!你把input的定义放在循环外声明就好了!
      

  7.   

    这个问题我也有过。hehe. 就是放在循环外就对了。