0

我有问题,myStringList.insertLast(name) 我不确定是否需要更改.insertLast其他内容。该错误表示无法将名称解析为变量。

public class TestLinkedList
{
  public static void main(String [] args)
  {  

  // define an Integer linked list MyIntList
  LinkedListClass<Integer> MyIntegerList = new LinkedListClass<Integer>();

  // intitialize the list
  MyIntegerList.initializeList(); 

  // insert a last element 5, then 6, and 7
  MyIntegerList.insertLast(5);
  MyIntegerList.insertLast(6);
  MyIntegerList.insertLast(7);

  // print the list
  MyIntegerList.print();  


   // insert first element 8
   MyIntegerList.insertFirst(11);

   // print the list 
   MyIntegerList.print(); 


  // define a String linked list MyStringList
  LinkedListClass<String> MyStringList = new LinkedListClass<String>();


  // initialize the list
  MyStringList.initializeList();  

  // insert last element Chris ,then Tom, and Bo
  MyStringList.insertLast(Chris);
  MyStringList.insertLast(Tom);
  MyStringList.insertLast(Bo);

  // print the list
  MyStringList.print();

  // insert first element Bo
  MyStringList.insertFirst(Anna);

  // print the list  
  MyStringList.print();


  }
}

我收到的实际错误如下:

4 errors found:
File: C:\Users\GreatOne\Desktop\Master Folder\LinkedList\LinkedList\TestLinkedList.java  [line: 36]
Error: Chris cannot be resolved to a variable
File: C:\Users\GreatOne\Desktop\Master Folder\LinkedList\LinkedList\TestLinkedList.java  [line: 37]
Error: Tom cannot be resolved to a variable
File: C:\Users\GreatOne\Desktop\Master Folder\LinkedList\LinkedList\TestLinkedList.java  [line: 38]
Error: Bo cannot be resolved to a variable
File: C:\Users\GreatOne\Desktop\Master Folder\LinkedList\LinkedList\TestLinkedList.java  [line: 44]
Error: Bo cannot be resolved to a variable
4

2 回答 2

0

字符串必须用双引号 (") 括起来。您的编译问题的解决方案如下:

  MyStringList.insertLast("Chris");
  MyStringList.insertLast("Tom");
  MyStringList.insertLast("Bo");

  ...

  // insert first element Bo
  MyStringList.insertFirst("Anna");
于 2013-07-19T04:06:56.177 回答
0

名称是字符串,在java中你必须使用“”。

   MyStringList.insertLast("Chris");
   MyStringList.insertLast("Tom");
   MyStringList.insertLast("Bo");  
   MyStringList.insertFirst("Anna");
于 2013-07-19T04:08:18.957 回答