Java FlowCharts Operators
Java FlowCharts Operators
Java FlowCharts Operators
Planning Programs
There are two ways of planning a program; 1. Pseudo-code = makes use of English statements to plot the program 2. Flowcharts = use graphical symbols
Example
class VariablesExample { public static void main (String args[]){ //variables are declared and assigned int N1 = 50; int N2 = 13; int tot; //the total of variables N1 and N2 //is stored in tot tot = N1 + N2; //Finally, we can show the result System.out.println(tot); } }
Pseudo-code Plan
Flowchart Plan
N1 = 50 N2 = 13 tot = N1 + N2
Display tot
End
We plan our programs in order to know what we will be doing before we start coding
With a plan it will be much easier to know what structure our program will have
Planning makes programming much easier
Flowcharts
A flowchart is basically a graphical presentation of our program A flowchart is very is to read and understand Flowcharts break down our programs into many steps
Flowchart Symbols
Terminator
The terminator is used to show 1. The start and 2. The end of a program
START END
Process
N1 = 50 N2 = 13
Decision
Decision are used when we have a comparison Decisions have two outputs which are YES or NO.
Is it Raining ?
YES
NO
Input/Output
The Input/ Output symbol is used 1. When the program requires and input 2. When the program results in an output
Display tot
Try it out
class Variable{ Create public static void main (String args[]){ //variables are declared and assigned 1. The pseudo-codes plan int N1 = 20; 2. The flowchart plan int N2 = 10; int tot; for the following program; int tot2; //tot1 and tot 2 declared tot = N1 + N2; tot2 = N1 N2; //Finally, we can show the result System.out.println(tot2); } }
Arithmetic Operators
The basic arithmetic operators ; 1. + (addition) These are called 2. - (subtraction) binary operators 3. / (division) because they need 4. * (multiplication) to use at least two 5. % (remainder) variables
Unary Operators
These only need one variable 1. ++ (increment by 1) 2. -- (decrement by 1) 3. variable += x (same as variable = variable + x)
variable -= x (same as variable = variable - x) 5. variable *= x (same as variable = variable * x) 6. variable /= x (same as variable = variable / x) 7. variable %= x (same as variable = variable %
4.
Combining Operators
1. 2. 3. 4. 5.
Use of Brackets
When we use brackets in our formula we are telling the program which operations to calculate first
X = (10 + 4) * 3 / 2; (10 + 4 ) * 3 / 2 14 * 3 / 2 42 / 2 21