English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi i have written this program in java but the following error appears at this line: System.out.println(List L + "=======\n"); (the error says that ')' is expected). Here is the complete program.
import java.util.*;

class myList1
{

public static void printList(List L)
{
for (int i=0;i System.out.println(List L + "=======\n");
}



public static void main(String[] args)
{

List names = new LinkedList();

names.add("Jones, M ");
names.add("Smith, J ");
names.add("Bloggs, F ");
names.add("Thompson, A ");
names.add("McCullough, G");
names.add("Ling, Y ");

printList(names);

}

}

What could the problem be? I am trying to complete a method that for each item in L in turn (starting at position 0, counting in i, for a total of L.size() times): Get the string item at position i, and print it; At the end, print a final underline.

2007-02-19 07:08:07 · 5 answers · asked by Princess Peach 3 in Computers & Internet Programming & Design

5 answers

replace System.out.println(List L + "=======\n");
with System.out.println( L + "=======\n");

List L is defining a variable of type List. to refer to the variable just use the name.

2007-02-19 07:12:11 · answer #1 · answered by adr41n 3 · 1 1

try this
public static void printList(List L)
{
for(int i = 0; i < L.size(); i++)
{
System.out.println(L[i]);
}
System.out.println("=======" + "\n");
}

At the moment you don't have a fully constructed for loop and even if it was fully done it would print the line "=======\n" for every item in the list L. From what I understand you just wanted printed at the end once so it needs to be put outside of the for loop.

2007-02-19 07:17:16 · answer #2 · answered by Anonymous · 0 0

Why roll your person while there is in all hazard a calendar widget you are able to reuse? via the way, the Java API itself supplies many clever training and interfaces: Date, Calendar, GregorianCalendar, DateFormat, and SimpleDateFormat.

2016-10-16 00:51:58 · answer #3 · answered by ? 4 · 0 0

The underlines should go outside the loop. They should look like this:
System.out.println("=======\n");


Inside your loop, you can do System.out.println(L[i]);

2007-02-19 07:14:40 · answer #4 · answered by Vegan 7 · 1 0

hmmmm, there doesnt seem to be a problem.

2007-02-19 07:15:23 · answer #5 · answered by Anonymous · 0 1

fedest.com, questions and answers