mercredi 8 mai 2019

How to use variable from an If-Else statement inside Try-Catch (Java)

How to use a variable from an if-else statement inside Try-Catch in Java?

String value1 = "sample"; 
String value2 = "sample";
int a;

try 
{

    if(value2.equals(value1))
    {
        a = 1;
    }
     int b = a;

catch (Exception e)
{
    System.out.println("Update Error!");
}

The 'a' in (int b=a;) has an error that says "Variable might not have been initialized". How do i use that variable?

Aucun commentaire:

Enregistrer un commentaire