variable types
Know how to declare and initialize variables of the following type:
int
double
char
boolean
String
‘Declare and initialize a variable’ means make a variable and give it a value.
You can just declare a variable with a type and name:
All variables need to be declared (given a type and a name) and must be given a value (initialized) before they can be used.
You can just declare a variable with a type and name:
int count;Then later in your code you can initialize it to hold a value:
count = 10;Or you can declare and initialize it all in one line of code:
int count = 10;Here are some examples of declaring and initializing variables for all the other data types you need to know for Level 0:
// doubles are for decimals double price = 1.75; // char is for a single character char letterE = 'E'; // booleans are either true or false boolean isFriday = true; // Strings are for text String school = "The League";Remember, String is capitalized, String values always have double quotes around them and char values are surrounded by single quotes.
All variables need to be declared (given a type and a name) and must be given a value (initialized) before they can be used.