Java Programming Language
LESSON 2 (operations,arrays,loops)
Hayk Avdalyan
Naming
Variable names are case-sensitive
Beginning with a letter, the dollar sign "$", or the underscore character "_" is allowed
Subsequent characters may be letters, digits, dollar signs, or underscore characters.
By convention, you should name your variables using “camel case”, i.e. if the name
consists of only one word, it is all lowercase letters. If it consists of more than one word,
the first letter of each subsequent word is capitalized.
Also by convention, constants are all capitalized and contain underscore.
Hayk Avdalyan
String
Find String functions yourself
Hayk Avdalyan
The Arithmetic Operators:
A=10,B=20
Hayk Avdalyan
The Relational Operators
A=10,B=20
Hayk Avdalyan
The Logical Operators
Logical And - (expression1) && (expression2)
returns true if expression1 and expression2 are true, otherwise – false
Logical Or - (expression1) || (expression2)
returns false if expression1 and expression2 are false, otherwise – true
Logical Not - !(expression) returns false if expression is true,
otherwise – true
Hayk Avdalyan
The Bitwise Operators A=60,B=13
Hayk Avdalyan
The Assignment Operators
The same way
Hayk Avdalyan
Arrays
Arrays are containers that hold a fixed number of values of a certain type. The length of an array
is fixed and is declared when the array is created.
To declare and array of ten integer elements:
Hayk Avdalyan
Initialize array
or
Hayk Avdalyan
Initialize array
Hayk Avdalyan
If/else statement
Hayk Avdalyan
If/else statement
Expression ? statement1:statement2
Hayk Avdalyan
Switch statement
Unlike if/else statements, the switch statement can have a number of possible execution paths.
A switch works with the byte, short, char, and int primitive data types.
From Java 8 String can be used in switch.
Also switch excepts Enum type (will be discussed in future).
Hayk Avdalyan
Switch statement
Hayk Avdalyan
While loop
Hayk Avdalyan
For Loop
Hayk Avdalyan
Tasks
1.
Char is given. Array is given.
If char is ‘A’ print maximal element in array. If it is “B” print minimal element.
Otherwise print mean value of maximal and minimal elements.
2.
Bubble sort.
Hayk Avdalyan