-1
瞭解它的工作原理,請參閱註釋。我無法從我的LinkedList類中調用客戶端中的方法
很明顯,它不僅僅在客戶端。我無法調用任何我創建的方法。對於我的任務,我應該在一個類中創建這些方法,然後在客戶端中實現它們。我甚至無法在最初的課程中調用這些方法。不知道爲什麼。
import java.util。*;
public class Driver5
{
public static final int SENTINEL = 0;
public static void main(String[] args)
{
int value = 1;
Scanner keyboard = new Scanner(System.in);
LinkedList<Intcoll5> P = new LinkedList<Intcoll5>();
while(value != SENTINEL)
{
if (value > 0)
{
P.**insert**(value);
}
}
}
}
仍然工作的一些方法,只是想調用insert()
import java.util.LinkedList;
import java.util.*;
public class Intcoll5
{
LinkedList<Integer> c = new LinkedList<Integer>();
ListIterator<Integer> I = c.listIterator();
public Intcoll5(int i)
{
c = new LinkedList<Integer>();
}
public void insert(int i)
{
Integer I = new Integer(i);
if (!c.contains(I))
{
c.addFirst(I);
}
}
public void copy(Intcoll5 obj)
{
while (I.hasNext())
{
}
}
public boolean belongs(Integer i)
{
return true;
}
public void omit(Integer i)
{
if (c.contains(i))
{
c.remove(i);
}
}
public int get_howmany()
{
int i = 0;
while (I.hasNext())
{
i++;
}
return i;
}
public void print()
{
while (I.hasNext())
{
Integer n = I.next();
System.out.println(n.intValue());
}
}
public boolean equals(Intcoll5 obj)
{
return true;
}
}
只是 「插入」 在客戶端所強調的,錯誤是: 「找不到符號」。
因此,如果我想將類實現到客戶端,我該怎麼做?因爲我有那個插入方法,所以我如何在客戶端調用它?謝謝。 – HelloKomputer
查看我的更新回答, –
'Intcoll5'表示一個整數列表。 'LinkedList'是'Intcoll5'的列表,因此是lists_的_list。你確定這就是你想要的嗎?如果是這樣,那麼它看起來像你想要在整數列表的_one_中插入一個整數,但是哪一個呢? –
ajb