Class Notes for Variables |
|
// int - variable that hold integer data
int a = 10;
// double - variable that holds decimal data
double b = 3.14159;
// char - variable that holds a single character
char c = 'C';
// boolean - variable that is either true or false
boolean d = false;
// String- variable that holds text data
String e = "Hello World";
// The symbol = is called the assignment operator; it assigns values to variables
// it does not check/declare equality
// Declaring a variable - telling Java the type and name of a variable
int i;
// Initializing that variable - setting the variable to a value
i = 32;
System.out.println(i);
// Declaring and Initializing on the same line
int j = 32;
// A double can store an int but NOT the other way around
double doubleNum = 10.5;
int intNum = 5;
doubleNum = intNum;
System.out.println(doubleNum);
double doubleNum2 = 10.5;
int intNum2 = 5;
//intNum2 = doubleNum2; // does not work
// Scientific Notation
System.out.println(1.234E4);
// Variable names can not start with a number and should be camel cased
// The only symbol it can contain is the _ underscore
Videos |
|
lesson2_part1.swf | |
File Size: | 9847 kb |
File Type: | swf |
lesson2_part2.swf | |
File Size: | 4532 kb |
File Type: | swf |
lesson2_part3.swf | |
File Size: | 2842 kb |
File Type: | swf |