Where do I have to declare the variables?

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-java/lessons/introduction-to-java/exercises/variables?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
my code has an error
Variables.java:6: error: variable myNumber is already defined in class Variables
int myNumber =42;
^
Variables.java:7: error: variable isFun is already defined in class Variables
boolean isFun = true;
^
Variables.java:8: error: variable movieRating is already defined in class Variables
char movieRating =‘A’;
^
3 errors

```

public class Variables {
int myNumber;
boolean isFun;
char movieRating;
int myluckynumber =7;
int myNumber =42;
boolean isFun = true;
char movieRating =‘A’;

public static void main(String[] args) {

}

}

<do not remove the three backticks above>

You should declare the variables only once. When a variable has been declared, you can use it without typing the date type before its name. So your code should look like this:

public class Variables {
int myNumber;
boolean isFun;
char movieRating;
int myluckynumber =7;
myNumber =42;
isFun = true;
movieRating =‘A’;

public static void main(String[] args) {

}

}

Sorry, my English is poor. I hope my answer will be helpful.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.