CC 102 - Fundamental Programming Lecture 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

JAVA PROGRAMMING

Lecture 5
Input / Output ,operators
and operator precedence and
control structure
Continuation …
Java Operators
Operators are used to perform
operations on variables and
values.
Java divides the operators into the
following groups:
Java
Operators ▪ Arithmetic operators
▪ Assignment operators
Java - are used to assign values to variables
Operators A list of all assignment operators:
Example:

Assignment
Java - are used to assign values to variables
Operators A list of all assignment operators:
Example:

Assignment
Java
Operators

Comparison
Java
Operators

Logical
Java control structure
Use the if statement to specify a block of Java
code to be executed if a condition is true.

syntax
if (condition) {
// block of code to be executed if the condition is true
}

example
if (20 > 18) {
System.out.println("20 is greater than 18");
}
Java control structure
If – else flowchart
Use the else statement to specify a block of code
to be executed if the condition is false.

syntax
if (condition) { // block of code to be
executed if the condition is true }
else { // block of code to be executed if the
condition is false }

example
int time = 20; if (time < 18) {
System.out.println("Good day."); }
else {
System.out.println("Good evening."); }
// Outputs "Good evening."
Laboratory :

Write a pseudocode , draw a flowchart and create a Java


program that will input 5 scores and compute the total
score and average of the 5 scores , if the average is less
than 75 it display “failed” or else “passed” .

You might also like