#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Variable tab problem


    i need help in publick prime i want it to use a "sito" tab from constructor i made before
    Code:
    package sitoeratostenesa;
    public  class SitoEratostenesa1{ 
                 SitoEratostenesa1 (int n){
                   
           boolean sito [] = new boolean[n+1];{
        
        for(int i=2; i<Math.sqrt(n); i++) {  
            if(sito[i]==true)          
                continue;
             for(int k=2*i; k<n; k+=i){
                 sito[k] = true;
               }
        }
        }
                 }
    public  boolean prime (int m){
                if (sito[m] == false){
                   System.out.print(m+" "); return true;}else{
                                            
             System.out.print(m+" ");   return false;}
    }
    
    }
  2. #2
  3. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    Moving to Java.
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    i want it to use a "sito" tab from constructor i made before
    Can you explain your problem?
    If you are getting error messages, copy the full text and paste it here.

    The posted code is poorly formatted which makes it hard to read and understand.
    One statement per line is the standard.
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Notice that in the constructor, you define a local array called sito. This is out of scope in the method prime.

    I would suggest you make sito an instance variable.

IMN logo majestic logo threadwatch logo seochat tools logo