Data
Basic skills
Variables
How to initialize a variable in two statements
Syntaxtype variableName;Example
variableName = value;
int counter; // declaration statement counter = 1; // assignment statement
How to initialize a variable in one statement
Syntaxtype variableName = value;Examples
int counter = 1; // initialize an int variable double price = 14.95; // initialize a double variable float interestRate = 8.125F; // F indicates a floating-point value long numberOfBytes = 20000L; // L indicates a long integer double distance = 3.65e+9; // scientific notation char letter = 'A'; // stored as a two-digit Unicode character char letter = 65; // integer value for a Unicode character boolean valid = false; // where false is a keyword int x = 0, y = 0; // initialize 2 variables with 1 statement