CC1 - Computing Fundamentals: Chapter 1 Data Types, Variables, and Algorithm
CC1 - Computing Fundamentals: Chapter 1 Data Types, Variables, and Algorithm
{ - start of a block
} – end of a block
Explanation
// Your program begins with a call to main().
–9,223,372,036,854,775,808
long 64
to 9,223,372,036,854,775,807
–2,147,483,648
int 32 to
2,147,483,647
• byte z, x;
short
• short is a signed 16-bit type. It has a range
from –32,768 to 32,767. It is probably the
least-used Java type.
• short s;
• short t;
int
• The most commonly used integer type is int. It
is a signed 32-bit type that has a range from –
2,147,483,648 to 2,147,483,647.
• int a;
• int b;
long
• long is a signed 64-bit type and is useful for
those occasions where an int type is not large
enough to hold the desired value. The range
of a long is quite large.
• long c;
• long d;
Floating-Point Types
• Floating-point numbers, also known as real
numbers, are used when evaluating
expressions that require fractional precision.
Approximate
Name Width in Bits
Range
4.9e–324 to
double 64
1.8e+308
1.4e–045 to
float 32
3.4e+038
float
• float can be useful when representing dollars
and cents. Here are some example float
variable declarations:
• boolean b = false;
• boolean a = true;
Variables
• In Java, all variables must be declared before
they can be used. The basic form of a variable
declaration is shown here:
• type identifier [ = value ], [ identifier [= value ]
…];
ALGORITHM
Algorithm
• a process or set of rules to be followed in
calculations or other problem-solving
operations, especially by a computer.
Examples
• Write an algorithm to add two numbers entered
by user.
• Step 1: Start
• Step 2: Declare variables num1, num2 and sum.
• Step 3: Read values num1 and num2.
• Step 4: Add num1 and num2 and assign the result
to sum. sum←num1+num2
• Step 5: Display sum
• Step 6: Stop
Examples
Pseudo Code:
Write "Please enter a number"
Read colornum
If (colornum >0 and colornum <= 10)
Write blue
else If (colornum >0 and colornum <= 20)
Write red
else If (colornum >0 and colornum <= 30)
Write green
else
Write "not a correct color option"