Chapter 2 Basics in Java Programming
Chapter 2 Basics in Java Programming
int highScore ;
type name
3 AU HHC Information Technology. Dept. By Megersa.O 1/17/2021
Creating Variables (continued)
System.out.println(“Hello,
World”);
You have already used statements to create a variable
and assign it a value.
- byte smallValue;
smallValue = -55;
- int pageCount = 1250;
- long bigValue = 1823337144562L;
double g = 7.7e100 ;
double tinyNumber = 5.82e-203;
float costOfBook = 49.99F;
Example:
boolean monsterHungry = true;
boolean fileOpen = false;
Example:
char firstLetterOfName = 'e' ;
char myQuestion = '?' ;
Real Numbers
Data Type Description
• Examples:
3 + 5 // uses + operator
14 + 5 – 4 * (5 – 3) // uses +, -, *
operators
1. Arithmetic operators
2. Assignment operator
3. Increment/Decrement operators
4. Relational operators
5. Conditional operators
double x = 63;
double y = 35;
System.out.println(x / y);
Ouput: 1.8
int x = 3;
int y = 5;
boolean result;
3) result = (x != x*y);
now result is assigned the value true because the product of
x and y (15) is not equal to x (3)
&& AND
|| OR
! NOT
Conditional operators can be referred to as boolean
operators, because they are only used to combine
expressions that have a value of true or false.
x y x && y x || y !x
1/17/2021
AU HHC Information Technology. Dept. By Megersa.O
36
Examples of Conditional Operators
boolean x = true;
boolean y = false;
boolean result;
(x || y) evaluates to true
(true && x) evaluates to true
(x || y)
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/opsummar
y.html