1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Java linklist Code

Discussion in 'Java' started by cyrow, Nov 24, 2007.

  1. cyrow

    cyrow New Member

    Nov 19, 2007
    Likes Received:
    Trophy Points:
    1) read from output file
    eg: 1222222 + 2333333
    3444444 - 9999999
    6666555 * 7

    2) For addition and sutraction, Number1 and Number2 should be large integers and must be stored in a link list.
    eg.output = 1222222 + 2333333 =

    3) For multiplication, Number1 should be stored in a link list and the small integer in a variable.
    output = 66666555 * 7 =

    4) Write to output file

    When I try to read from the output file, this error is generated
    !!Error :Variable last might not have been initialize
    Help me to clarify the issue becuase i don't think I have to initialize "last" as it has already been declared as a node type.


    import java.io.*;
    import java.util.*;
    class Node{
    	int bigInt;
    	Node next;
            bigInt = 0;
    		next = null;
    	public Node(int bigInt){
    		bigInt = 0;
    		next = null;
    public class BuildList{
    	public static void main(String[] args)throws IOException{
    	Scanner in = new Scanner(new FileReader("input.txt"));	
    	FileWriter out = new FileWriter("output.txt") ;
    	Node top, np, last;
    	top = null;
    	//Reading data from input.txt
    	int bigInt = in.nextInt();
    		if (bigInt > 100){//only bigInt numbers are added to the list for add, subtract and multiply
    			np = new Node(bigInt);
    		if (top==null){
    			top = np;
    			last.next = np;
    			last = np;
    			bigInt = in.nextInt();
    }//end main
    }//end class check
    Last edited by a moderator: Nov 25, 2007

Share This Page