I am new to programming, I am trying to learn how to program in Java through some old programs I found online, and yet I seem to be struggling. This is the program I wrote to fill a linked list with 10 numbers using a loop and then just printing the numbers out. I can't seem to figure out what is wrong with it. Any suggestions would be welcome.

//Vivian Boykin
//W0411888
//The Linked List Part I: JAVA (or bust)
//Assignment 3


import java.util.Scanner;
import java.io.*;
import java.util.*;

public class linkedListProg{



public static void main(String[] args){


       linkedListProg l = new linkedListProg();
       System.out.println("Welcome!! Press ENTER to retrieve your Linked List");
       System.out.println("otherwise please stay on the line");
       System.out.println("and a representative will be with you shortly");
}

    linkedListProg(){
        data front;
        current tail;
    front = null;
    for(int j = 0; j <10; j++){
        current = makeNode(j);
                if(front == null){  
                    front = current;
                }

        else{
            tail = findTail(front);
            tail.next = current;
            }


    System.out.println("The linked list you requested");
        System.out.println("written in Java");
        System.out.println("filled with a simple loop");
        current = front;
        while(current != null){
            System.out.println("data =" + current.iNum);
            current = current.next;
}

} 

     data  makeNode(int num){
         data newNode;
     newNode = new data();
         newNode.iNum = num;
         newNode.next = null;
    }


        data findTail(data front){
        data current;
        current = front;
        while(current.next != null){
        current = current.next;
}
    return current;
}

    class data{
        int iNum;
          data next;
    }

here are the errors I am getting. I am using the jgrasp compiler.

linkedListProg.java:51: error: ';' expected
    data  makeNode(int num){
                  ^
linkedListProg.java:51: error: ';' expected
    data  makeNode(int num){
                          ^
linkedListProg.java:59: error: ';' expected
        data findTail(data front){
                     ^
linkedListProg.java:59: error: ';' expected
        data findTail(data front){
                                ^
linkedListProg.java:71: error: reached end of file while parsing
    }
     ^
5 errors

Your {} are all messed up - eg on line 49 you have the } that closes the class definition, but there is obviously more code following that which should be in the class.
The best way to sort out this kind of problems is to go through the code fixing the indentation and ensuring the {} are correctly lined up and paired up. Making random changes in the hope that they will work is a bad idea, it will only make things worse.

This article has been dead for over six months. Start a new discussion instead.