0

there is a section in a school project where I need to convert input to a double, to be multiplied by another double, and I keep getting "error: int cannot be dereferenced" for the following code:

        int a = Integer.parseInt(input.readLine());
        int aa = a.nextInt();
        int aaa = Math.pow(1 + a, aa);
        amount1 = (aaa * 13.49);
        amount += amount1;

Any ideas as to what I'm doing wrong?

1
  • An int is a primitive, not an object. This means you cannot call methods on it. Commented May 10, 2013 at 18:45

2 Answers 2

1

You cannot call a method on an int, but you are trying:

a.nextInt();

Assuming that input is a Scanner, I think that you want to call nextInt on input instead.

EDIT

Scanner didn't exist in 1.4.2, so just do for aa what you already did for a -- parse the next line of input.

Sign up to request clarification or add additional context in comments.

10 Comments

How do I fix this? I am new to Java.
Hint: Use the same for aa as you used for a
Also I can't use scanner, because I have to use Java 1.4.2, so instead I'm using BufferedReader
@user1965245 - You need to read the line into a String and then break it apart into successive pieces. Apply parseInt to the pieces, not the entire string.
(And you can use String.split to break the line apart.)
|
0

Difficult to understand without knowing the format you are reading: e.g If your input source has a single integer per line - simply repeat the first line

int aa = Integer.parseInt(input.readLine());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.