DATA_TYPE VARIABLE_NAME ;
int number; double interest; char ch; bool finished;
VARIABLE_NAME = VALUE
number = 5; interest = .065; ch = 'x'; finished = false;
DATA_TYPE VARIABLE_NAME = VALUE ;
int number = 5; double interest = .065; char ch = 'x'; bool finished = false;;
number = 5You should not say "number equals 5"
rate $name _init first_name value1 value_2 _
1st_name first name
d = s * t
course_id student_name first_name
first_name First_Name First_name FIRST_NAME
int number = 1; System.out.println(number);
5.5 + 7 9 - 3.1
Operator | Meaning | Example | Result |
---|---|---|---|
+ | addition | 2 + 2 | 4 |
– | subtraction | 53 – 18 | 35 |
* | multiplication | 3 * 8 | 24 |
/ | division | 4 / 2 | 2.4 |
% | remainder or modulo | 19 % 5 | 4 |
7.0 / 2.0 = 3.5
17 / 5
17 / 5 = 3 17 % 5 = 2
10 / 5 = 2 10 % 5 = 0
x % 2 = 0 // x is even x % 2 = 1 // x is odd
x % 10 // the last digit of x
ssNum % 1000 // the last four digits of the social security number
int number = 5; char ch = 'X;'
char
data type can only hold one characterchar
because it has more than one characterString
String
variable like like this
String message;
char
variables contains a single characterchar ch = 'Z'
String
variables contain many charactersString
literals use double quotes
String message = "Hello world!"
String s1 = "foo"; String s2 = "bar"; System.out.println(s1 + s2);the output is
foobar
String first = "John"; String last = "Smith"; System.out.println(first + " " + last);the output is
John Smith
int result = 5; System.out.println("The answer is " + result);gives
The answer is 5
int n1 = 5; int n2 = 10; System.out.println(n1 * n2);the output would be
50
50
int
variable
int number = 5;
double
double number = 5;
String
String number = "5";
char
char number = '5';
int
or double
String
and char
is concatenate
char
char
only hold a single character