int can't be dereferenced

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shana07
    Contributor
    • Jan 2007
    • 280

    int can't be dereferenced

    Good Day!
    How to tackle 'int can't be dereference'?. What does it mean?
    Please give me some pointer....than ks guys

    Code:
    public static void main(String[] args) 
        {
             int opcode = GCD; 
            
             String out="";
            
            int b2 = 300;
            int b1 = 700;
               
             switch (opcode) 
             {           
                case GCD:       out = b1.gcd(b2).toString(); // THE ERROR COMES FROM HERE....
                                break;
                default:        throw new BigAlException("invalid operation");
            }
                                
              System.out.println(out);
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shana07
    Good Day!
    How to tackle 'int can't be dereference'?. What does it mean?
    Please give me some pointer....than ks guys

    Code:
    public static void main(String[] args) 
    {
    int opcode = GCD; 
     
    String out="";
     
    int b2 = 300;
    int b1 = 700;
     
    switch (opcode) 
    { 
    case GCD: out = b1.gcd(b2).toString(); // THE ERROR COMES FROM HERE....
    break;
    default: throw new BigAlException("invalid operation");
    }
     
    System.out.println(out);
    b1.gcd(b2).toSt ring b1 is an int and you are trying to call a method on it! Remember you can only call methods on objects not on primitives.

    Comment

    • shana07
      Contributor
      • Jan 2007
      • 280

      #3
      Originally posted by r035198x
      b1.gcd(b2).toSt ring b1 is an int and you are trying to call a method on it! Remember you can only call methods on objects not on primitives.
      How should I do to call gcd method by parsing int b1 and int b2?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by shana07
        How should I do to call gcd method by parsing int b1 and int b2?
        Wrap then in BigInteger

        Comment

        • shana07
          Contributor
          • Jan 2007
          • 280

          #5
          Originally posted by r035198x
          Wrap then in BigInteger
          such this?
          Code:
          BigInteger b1=null, b2=null;
                         
                  b2 = receiveNumber(arrayArgs[1]);
                  b1 = receiveNumber(arrayArgs[0]);
          btw, is there any gcd method in integer java core class? I mean no BigInteger?
          Is like I want to skip BigInteger..

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by shana07
            such this?
            Code:
            BigInteger b1=null, b2=null;
             
            b2 = receiveNumber(arrayArgs[1]);
            b1 = receiveNumber(arrayArgs[0]);
            btw, is there any gcd method in integer java core class? I mean no BigInteger?
            Is like I want to skip BigInteger..
            You can always check the docs. Does your receiveNumber method return a BigInteger?

            Comment

            • shana07
              Contributor
              • Jan 2007
              • 280

              #7
              Originally posted by r035198x
              You can always check the docs. Does your receiveNumber method return a BigInteger?
              it does....
              Code:
               BigInteger b = null;
                      
                      b = new BigInteger(str);  
                      return b;
              I am just wondering, is there any normal gcd (int a, int b) in other java core class as this method calls BigInteger gcd.....

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by shana07
                it does....
                Code:
                 BigInteger b = null;
                 
                b = new BigInteger(str); 
                return b;
                I am just wondering, is there any normal gcd (int a, int b) in other java core class as this method calls BigInteger gcd.....
                You should just write your own method.

                Comment

                Working...