How to use the value of variable from if/else tree as value of variable for a while loop afterwards
<p>Here is my program code as I have it written so far. It's saying I haven't initialized answer. I want to use the value of answer after the if/else tree executes to convert the number into asterisks.</p>

<pre><code>import java.io.*;
import java.util.*;

public class Project5 {
    public static void main(String[] args){
        System.out.println("Please enter a formula of this form:operator,operand,operand(ex. add,2,2):");
        // wanted to change things but was not sure how far I was allowed to go so I used commas instead of spaces
        //was trying to split with a delimiter but kept getting an error [Ljava.lang.String;@55e83f9
        Scanner input = new Scanner(System.in);
        String formula = input.nextLine();
        System.out.println(formula);
        String oper = formula.substring(0,3);
        System.out.println(oper);
        String fnum = formula.substring(4,5);
        System.out.println(fnum);
        String snum = formula.substring(6,7);
        System.out.println(snum);
        double freal = Integer.parseInt(fnum);
        System.out.println(freal);
        double sreal = Integer.parseInt(snum);
        double answer;
        if (oper.equalsIgnoreCase("add") == true){
            answer = freal+sreal;
            System.out.println(answer);
        }
        else if(oper.equalsIgnoreCase("subtract") == true){
                 answer = freal-sreal;
            System.out.println(answer);
        }
        else if(oper.equalsIgnoreCase("multiply") == true){
                 answer = freal*sreal;
            System.out.println(answer);
        }
        else if(oper.equalsIgnoreCase("divide") == true){
                 answer = freal/sreal;
            System.out.println(answer);
        }
        else
            System.out.println("not valid.");

        while(answer &gt; 0){
            System.out.print("*");
            answer--;
    }
}}
</code></pre>
