mardi 28 avril 2020

cannot resolve method value?


public class week2 {
    public static int numbers(int x, int y) {
        int value = x - y;
        System.out.println("Value is " + value + ".");
        return value;
    }


    public static void main(String[] args) {
        numbers(20,10);
        if(value == 1)
        {
            System.out.println("yo");
        }
        else{
            System.out.println("whatsup");
        }

    }
}

Why does the line if(value == 1) show the error that value cannot be resolved? Didn't I mention that value = x-y in my method? edit: ahh thank you guys I did not know that you can't access value outside the method

Aucun commentaire:

Enregistrer un commentaire