-3

My Code:

public static void verschluesseln(int m) {
    if(m < n) {
            int c =  m.modPow((int) n, oeffentlicherSchluessel[0]);
    }

Error:

.java:51: error: int cannot be dereferenced
            int c =  m.modPow((int) n, oeffentlicherSchluessel[0]);
                      ^

This did run in another project of mine. This is why I am heavily confused by this error.

  • 4
    No, it didn't. You may not call methods on primitive types. modPow() is a method of the BigInteger class. You needs an instance of BigInteger to call it. https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html#modPow-java.math.BigInteger-java.math.BigInteger- – JB Nizet Nov 11 '18 at 12:31
  • 1
    `int` is a primitive and no primitive has a method in Java. You might have been thinking of another language e.g. C# has this. – Peter Lawrey Nov 11 '18 at 12:37
  • Or, perhaps you wrote your own modPow method just for ints in your other program. – President James K. Polk Nov 11 '18 at 22:13
  • @JamesKPolk You would still not be able to call it on an `int` as in the displayed code. – Maarten Bodewes Nov 13 '18 at 04:00

1 Answers1

2

modPow is BigInteger method, you can't use it with int. It also receives BigInteger as parameters, not int

BigInteger c = BigInteger.valueOf(m).modPow(BigInteger.valueOf(n), BigInteger.valueOf(oeffentlicherSchluessel[0]));
Guy
  • 46,488
  • 10
  • 44
  • 88