Variables, data types and the assignment operator Flashcards
Variable
Location in the computer’s memory that is used to store data in a program
Must be declared with an identifier and type
Identifier consists of
Letters digits underscores dollar signs It also cannot start with a digit
Difference between double and single quotes
Double - String
Single - Char
Number literal
Constant number that appears directly on code
Local-variable inference
Programmer can use var instead of declaring the type of variable
When can var be used
Local variable declarations with initializers
For loops
Try statements
When can var not be used
Global variables
Method signature
Any case where the compiler cannot infer type
How to fix a logic error in which the computer will not let the user input a second value
Extra in.nextLine(); to accommodate “Enter” key in queue
Named constants
A constant must be declared and intialized in the same statement.
e.g. final double PI = 3.14159;
final int SIZE =3;
When is the remainder negative
Remainder is only negative when dividend is negative
Augmented assignment operators
Operators that can be combined with the assignment operator.
e.g. +=; -=; *=; /=
++var
preincrement: Increment var by 1, and use the new var value in statement
var++
postincrement: Increment var by 1 but use the original var value in the statement.
–var
predecrement: Decrement var by 1, and use the new var value in the statement.
var–
postdecrement: Decrement value by 1 and use the original var value in the statement.