1

So in this section of my program I'm trying to make the program re-ask for input from the user.

The problem is that is says the int have already been declared. But how do I get the input for the question again?

Scanner keyboard = new Scanner(System.in);

System.out.println("Please enter possible and actual points for participation: ");
int pparticipation = keyboard.nextInt();
int aparticipation = keyboard.nextInt();

while (aparticipation > pparticipation || pparticipation < 0){
   System.out.println("Please enter possible and actual points for participation: ");
   int pparticipation = keyboard.nextInt();
   int aparticipation = keyboard.nextInt();
}

3 Answers 3

2

You declared the variables twice. Removing the "int" from the variables in the loop should get it working.

int aparticipation; that is declaring a variable. To assign a value to the variable after that you just do aparticipation = keyboard.nextInt();

You already declared it so you dont have to tell the compiler that its an int again.

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

1 Comment

Wow stupid mistake. Thanks for pointing it out, that did the trick!
1

The error is occurring because you are trying to declare pparticipation and aparticipation again within the loop. Remove the type (int) from in front of those two variables.

Comments

0

All you have to do is to change the following :-

while (aparticipation > pparticipation || pparticipation < 0){
   System.out.println("Please enter possible and actual points for participation: ");
   int pparticipation = keyboard.nextInt();
   int aparticipation = keyboard.nextInt();
}

to

while (aparticipation > pparticipation || pparticipation < 0){
   System.out.println("Please enter possible and actual points for participation: ");
   pparticipation = keyboard.nextInt();
   aparticipation = keyboard.nextInt();
}

The variables are already declared, so don't do it again.

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.