I am new to java coming from C#.
If I have a string that gets set in an "if-statement" is there a way to carry that string's value to other if statements?
E.g. I set the String hi
to carry the text "hello" in an if statement, but now have a completely separate if statement, and would like to use the value set to the String hi
in the previous if statement.
My issue is that the veriable can't be set until certain things in the if statement happen.
if(add.equals(temp)) {
System.out.println ("What is the first number?");
numberone = listen.nextDouble ();
System.out.println ("What is the second number?");
numbertwo = listen.nextDouble ();
numberthree = numberone + numbertwo;
previousproblem = numberthree;
System.out.println ("The answer is " + numberthree);
}
So later on, in another if
statement I, need to reference previousproblem
, but it can't be set until this if
statement, as numberthree
isn't set until this statement.