how can i acess a variable outside of an if statement in java
- by themanepalli
i have defined a variable inside an if statement and I am trying to access it outside of that if statement now. now the error is saying that it cannot find the symbol which is because its being defined as an intance variable, is there a way i can change it so i can access it outside the variable? heres the code
if((e.getSource()==userOrder2)&& (orderType==1))
{
String buyO= userOrder2.getText();
int buyOrder= Integer.parseInt(buyO); //variable im trying to access
}
// trying to use buyOrder in a different if statement
if(orderType==1 && (stockPrice <= buyOrder))
{
orderResult.setText("The Stock" + (stockName2.getText()) + "was bought at" + stockPrice);
}