Why isnt my variable recongized within the parameter? (JAVA)

Status
Not open for further replies.

St4nley

Member
Apr 13, 2013
469
76
Code:
package pkgdo.dowhile;

public class DoDoWhile {
    //DO WHILE STATEMENT
    /* THIS STATEMENT IS CLAIMING TO ADD COUNT + 1 UNTILL COUNT IS LESS THAN 11
    * IT MUST LOOP ONCE AT LEAST SINCE WHILE IS AT THE BOTTON OF THE CODE*/
   
public static void main(String[] args){
        int count = 1;
        String hello = "word";
       
        do {
            Print("Count is: " + count);
            count++;
          } while (count < 11);
                                      }

   
        static void Print(String echo)  {
        System.out.println(echo);
       

       
        if (count > 8)  {
                  Print("Void NEXT");
}else{
        Print("Continue With Next Terms");
       
 
                        }
       

        }
       

  }

In my if statement the variable count which has been established in my main class isnt being recognized in this instance.
How come?
Thanks!
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
I'm no java expert, I only did a bit in university. But you're only declaring count in main(), not globalising it
 

St4nley

Member
Apr 13, 2013
469
76
Code:
public static void main(String[] args){
                int count = 11;
                String hello = "word";
                        if (count > 8)  {
                  Print("Void NEXT");
}else{
        Print("Continue With Next Terms");
       
        do {
            Print("Count is: " + count);
            count++;
          } while (count < 11);
}

                        }
       
static void Print(String echo)  {
        System.out.println(echo);
        }
       
}

Close thread, my logic wasn't correct. The IF Statement must be before the do statement it only makes sense, i thought of this after @m0nsta. replied it made be think of the order of the instances being ran by the compiler. Thanks
 
Status
Not open for further replies.

Users who are viewing this thread

Top