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;
}