Anda di halaman 1dari 2

Pseudojava document 2.2.

Output Statements
This is used for writing values to the screen.
1. Data Types  printf(“%...”, expression); //expression
evaluated and its value written to the screen
using the specified format.
The following data type can be used in your
pseudocode.
Data Type Declaring a variable
int int myInt; 3. Assignment Statement
double double myDouble;
char char myChar; The assignment statement is used to manipulate
boolean boolean myBoolean; (change value) values of variables. It has the following
String String myString; syntax:
variableName = expression;
1.1. Structured Data Types expression is either a value (called literal value), a
We will only consider one and two dimensional variable or any valid Java arithmetic or
arrays. Boolean/Logical expression. The assignment MUST
Example: int myInts[10]; be type compatible. For example, a double value can
and int myInts[10][20]; not be assigned to an int variable.

1.2. Naming Variables


You must name your variables to conform to the 4. Operators
following convention:
 Variable names MUST be meaningful, 4.1. Arithmetic Operators
except for indexing variables. The following operators are used in Java to form
 Variable names must start with a lowercase compound arithmetic expressions. BEDMAS is
letter and each new word should start with applied to evaluate expression involving arithmetic
an uppercase letter. The only exception is for operators.
class names: they start with uppercase Operator Meaning
letters. % Modulus
* Multiplication
A variable MUST be initialized before it can be / Division
used. + Addition
- Subtraction

2. Input/Output Statements Division, multiplication and modulus have the same


precedence and are evaluated from left to right.
2.1. Input Statements Subtraction and addition have the same precedence
These are used for reading input from the keyboard and are evaluated from left to right.
into variables.
 variableName = readInt(); //reads an int 4.2. Relational Operators
(integer) and assigns it to variableName. These are used to compare two values. The result is
 variableName = readDouble(); //reads a either true or false, never both.
double (real) and assigns it to variableName. Operator Meaning
 variableName = readWord(); // reads a > strictly greater than
String (character sequence) and assigns it to >= greater than or equal to
variableName. < strictly less than
 variableName = readLine(); // reads a <= less than or equal to
sequence of characters up to the Enter key == equal to
and assigns it to variableName. != not equal to

1
4.3. Logical Operators OR
These are used to form compound Logical (Boolean)
expressions. They combine two conditions. The
exception is the negation operator. switch (expression)
{
Operator Meaning case value1: statementBlock1;
|| or break;
&& and case value2: statementBlock2;
! not or negation break;
case value3: statementBlock3;
5. Selection break;
..
To choose (select) between alternatives depending .
case valuen: statementBlockn;
on a condition. Sometimes there is no second
break;
alternative.
default: statementBlockDefault;
5.1. One alternative if }

if (condition)
{
statementBlock; Note that in the switch the value of expression MUST
} be of integral type (byte, short, int, long, char).

5.2. Two alternatives if


6. Repetition
if (condition)
{ These structures allow one’s program to repeat a
statementBlock1; given set of statements depending on a condition.
}
else 6.1. while Loop
{
statementBlock2;
while (condition)
}
{
statementBlock;
5.3. Multiple alternatives if }

if (condition1) 6.2. for — Loop


{
statementBlock1; for (initialization; condition; update )
} {
else if (condition2) statementBlock;
{ }
statementBlock2;
OR }
. This looping structure can be written as a while loop.
.
.
else
{
statementBlockn;
}
2

Anda mungkin juga menyukai