Professional Documents
Culture Documents
- Assignment Operators
int num1,num2,num3,num4,num5,num6;
num 1 = 5;
// += addition assignment
num2 = 1
num2 += 4;
// -= subtraction assignment
num3 = 10;
num3 -= 7;
// *= multiplication assignment
num4 = 2;
num4 *= 2;
// /= division assignment
num5 = 12;
num5 /= 2;
// %= modulo assignment
num6 = 3;
num6 %= 2;
- Relational Operators
Note: this can be used in multiple datatypes. Using int for simplicity sake.
int num1, num2, num3;
num1 = 5
num2 = 9
num3 = 5
System.out.println(num1 == num3);
// true
System.out.println(num1 != num3);
// false
// > GREATER THAN - Checks if one value is greater than the other value
// false
// < LESS THAN - Checks if one value is lesser than the other value
// true
// >= GREATER THAN OR EQUAL - Checks if one value is greater or equal than the other
value
// true
// <= LESS THAN OR EQUAL - Checks if one value is lesser or equal than the other value
// true
- Logical Operators
Note: Look up "Truth Table" lesson on MMW.
int num1, num2, num3;
num1 = 5
num2 = 9
num3 = 5
// && Logical AND - Returns True if both the conditions mentioned are true.
// true
// || Logical OR - Returns True if one or both the conditions mentioned are true.
// true
// ! Logical NOT - Returns True if the condition mentioned is false and vice versa.
// false
- Decision Making
Pseudocode - It is a detailed yet readable description of what a computer program or
algorithm must do, expressed in a formally - styled natural language rather than in a
programming language.
Flowchart - It is a diagram that depicts a process, system or computer algorithm. It can also
be defiened as a diagrammatic representation of an algorithm or a step-by-step guide to
solving a task.
- Flow of Control
Flow of Control is the order in which a program performs actions. \
A branching statement or selection statement chooses one action from a list of two or
more possible actions.
A loop statement or iteration statements repeats an action again and again until some
stopping condition is met.
Sequence Structure may contain any number of steps, but when one task follows another
with no chance to branch away or skip a step, you are using a sequence.
- Flowchart
Flowline - Shows the process's direction by conneting two blocks with one another.
Decision - This symbol represents a decision you or your team need to make to get to the
next step of the process; Yes or No/ True or False.
"Or" Symbol - This indicated that the process flow continues in three or more branches.
Off - Page Connector - This symbol is used to connect two symbols that are of different
pages.
On - Page Connector - This dot can connect two symbols and replace long lines which
allows for a cleaner flow chart.
Example
public static void IfStatement() {
int grade;
grade = input.nextInt();
if (grade >=85) {
else
Output:
Input Grade: 89
- If..Else If
Example
if (num1 > 0) {
else {
- Compare String
Example
public static void compareString() {
if (name.equalsIgnoreCase("Jhon Benedict") ||
name.equalsIgnoreCase("Jhon") ||
name.equalsIgnoreCase("Benedict") ||
name.equalsIgnoreCase("Ben") ||
else if (name.equalsIgnoreCase("Panda")) {
name.equalsIgnoreCase("John")) {
else {
- Nested If
public static void nestedIf() {
int age;
double GWA;
System.out.print("Name: ");
name = in.nextLine().toLowerCase();
System.out.print("Address: ");
address = in.nextLine();
if (address.contains("valenzuela")) {
System.out.print("Age: ");
age = in.nextInt();
GWA = in.nextDouble();
}
} else {System.out.println("only 17-21 years old");