1) read from output file

    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.

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.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;
   = np;
            last = np;
            bigInt = in.nextInt();

}//end main
}//end class check

because you do

Node top, np, last;

Then, the very next time last is seen, it is in the else block and you are attempting to dereference it.

} else { = np;
  last = np;
  bigInt = in.nextInt();

Yep, as masijade pointed out, if the compiler sees that you have an execution path that could lead to a variable being used before an assignment has been made (as in your "if" clause above), it will warn you of that. If you assign a default value when you declare the variable, you'll be fine. Even if you want it to remain null you will need to declare that.


Just a very very minor point. It should be


JDK is Java Development Kit.
Jkd is different, they are my initials!