Я получаю 3 ошибки при компиляции программы, я пробовал несколько других способов, но все равно ничего не добился. Программа должна отобразить переданное содержимое LinkedList, затем найти переданный индекс String и распечатать его, а затем распечатать содержимое LinkedList в обратном порядке. Метод, позволяющий сделать все это, — это методы void в классе LinkedList.
Это LinkedList:
public class LinkedList {
private Node front;
private int count;
public LinkedList() {
front = null;
count = 0;
}
public void addToFront(String d) {
Node n = new Node (d, front);
front = n;
count++;
}
public int size() {
return count;
}
public boolean isEmpty() {
return (count == 0);
}
public void clear() {
front = null;
count = 0;
}
public String getFrontData() {
if (front == null)
return "Empty List";
else
return front.getData();
}
public Node getFront() {
return front;
}
//EX_1
public void set(int index, String d) {
if (index < 0 || index > size())
System.out.println("Cant add. Index Out of Bounds.");
else if (index == 0)
addToFront(d);
else {
Node curr = front;
for (int i = 0; i < index-1; i++)
curr = curr.getNext();
Node n = new Node(d, curr.getNext());
curr.setNext(n);
count++;
}
}
// EX_2
public void listAll(String d) {
Node curr = front;
boolean found = false;
int index = -1;
while (curr != null && ! found) {
index ++;
if (curr.getData().equals(d))
found = true;
curr = curr.getNext();
}
if (!found)
System.out.print("did not find Anything");
else
System.out.print(index);
}
// EX_3
public void printReverse() {
if (front == null)
System.out.print("The List is Empty");
else {
for (int i = size()-1; i >= 0; i--)
System.out.print(i + " --> ");
}
}
public void enumerate() {
Node curr = front;
while (curr!= null) {
System.out.print(curr);
curr = curr.getNext();
}
System.out.println();
}
}// Class
Это основная программа:
public class LinkedListDemo {
public static void main(String[] args) {
LinkedList str = new LinkedList();
str.set(0,"M");
System.out.println("Strings in the Linked List: " + str.set());
str.enumerate();
str.addToFront("M");
str.addToFront("T");
str.addToFront("N");
str.addToFront("T");
str.addToFront("L");
str.addToFront("H");
str.listAll("T");
System.out.println("Number of T's in the List: " + str.listAll());
str.enumerate();
str.addToFront("T");
str.addToFront("N");
str.addToFront("T");
System.out.print("Components of the list in Reverse: " + str.printReverse());
str.enumerate();
}// Main
}// Class
Это ошибка компилятора:
----jGRASP exec: javac -g LinkedListDemo.java
LinkedListDemo.java:8: set(int,java.lang.String) in LinkedList cannot be applied to ()
System.out.println("Strings in the Linked List: " + str.set());
^
LinkedListDemo.java:20: listAll(java.lang.String) in LinkedList cannot be applied to ()
System.out.println("Number of T's in the List: " + str.listAll());
^
LinkedListDemo.java:27: 'void' type not allowed here
System.out.print("Components of the list in Order: " + str.printReverse());
^
3 errors
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
Подробнее здесь: https://stackoverflow.com/questions/224 ... d-contents
Как отобразить содержимое метода void [закрыто] ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1761260906
Anonymous
Я получаю 3 ошибки при компиляции программы, я пробовал несколько других способов, но все равно ничего не добился. Программа должна отобразить переданное содержимое LinkedList, затем найти переданный индекс String и распечатать его, а затем распечатать содержимое LinkedList в обратном порядке. Метод, позволяющий сделать все это, — это методы void в классе LinkedList.
Это LinkedList:
public class LinkedList {
private Node front;
private int count;
public LinkedList() {
front = null;
count = 0;
}
public void addToFront(String d) {
Node n = new Node (d, front);
front = n;
count++;
}
public int size() {
return count;
}
public boolean isEmpty() {
return (count == 0);
}
public void clear() {
front = null;
count = 0;
}
public String getFrontData() {
if (front == null)
return "Empty List";
else
return front.getData();
}
public Node getFront() {
return front;
}
//EX_1
public void set(int index, String d) {
if (index < 0 || index > size())
System.out.println("Cant add. Index Out of Bounds.");
else if (index == 0)
addToFront(d);
else {
Node curr = front;
for (int i = 0; i < index-1; i++)
curr = curr.getNext();
Node n = new Node(d, curr.getNext());
curr.setNext(n);
count++;
}
}
// EX_2
public void listAll(String d) {
Node curr = front;
boolean found = false;
int index = -1;
while (curr != null && ! found) {
index ++;
if (curr.getData().equals(d))
found = true;
curr = curr.getNext();
}
if (!found)
System.out.print("did not find Anything");
else
System.out.print(index);
}
// EX_3
public void printReverse() {
if (front == null)
System.out.print("The List is Empty");
else {
for (int i = size()-1; i >= 0; i--)
System.out.print(i + " --> ");
}
}
public void enumerate() {
Node curr = front;
while (curr!= null) {
System.out.print(curr);
curr = curr.getNext();
}
System.out.println();
}
}// Class
Это основная программа:
public class LinkedListDemo {
public static void main(String[] args) {
LinkedList str = new LinkedList();
str.set(0,"M");
System.out.println("Strings in the Linked List: " + str.set());
str.enumerate();
str.addToFront("M");
str.addToFront("T");
str.addToFront("N");
str.addToFront("T");
str.addToFront("L");
str.addToFront("H");
str.listAll("T");
System.out.println("Number of T's in the List: " + str.listAll());
str.enumerate();
str.addToFront("T");
str.addToFront("N");
str.addToFront("T");
System.out.print("Components of the list in Reverse: " + str.printReverse());
str.enumerate();
}// Main
}// Class
Это ошибка компилятора:
----jGRASP exec: javac -g LinkedListDemo.java
LinkedListDemo.java:8: set(int,java.lang.String) in LinkedList cannot be applied to ()
System.out.println("Strings in the Linked List: " + str.set());
^
LinkedListDemo.java:20: listAll(java.lang.String) in LinkedList cannot be applied to ()
System.out.println("Number of T's in the List: " + str.listAll());
^
LinkedListDemo.java:27: 'void' type not allowed here
System.out.print("Components of the list in Order: " + str.printReverse());
^
3 errors
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
Подробнее здесь: [url]https://stackoverflow.com/questions/22431950/how-to-displaying-void-method-contents[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия