Class 9 ICSE - Java
Class 9th Java aims to empower students by enabling them to build their own applications introducing some effective tools to enable them to enhance their knowledge, broaden horizons, foster creativity, improve the quality of work and increase efficiency.
It also develops logical and analytical thinking so that they can easily solve interactive programs. Students learn fundamental concepts of computing using object oriented approach in one computer language with a clear idea of ethical issues involved in the field of computing
Class 9th java topics includes revision of class 9th, constructors, user-defined methods, objects and classes, library classes , etc.
Iterative Constructs
Sometimes we want our programs to execute a few set of instructions over and over again.
For Example :
- print numbers from 1 to 1000
- print multiplication table of 7, etc.
Iteration make it easy for us to tell the computer that a given set of instructions need to be executed
repeatedly.
Types of loop
Primarily there are three types of loops in java :
(i) While loop
(ii) do-while loop
(iii) for loop
while loop
- The while loop in Java is used when we need to execute a block of code again and again based on a
given boolean condition.
- We use while loop when the exact number of iterations are not known to us.
- If the condition never becomes false, the while loop keeps getting executed. Such a loop is known as
an infinite loop.
It is also called as "entry control loop"
Syntax :
Example :
int i=10;
while(i>0){
System.out.println(i);
i--;
}
⇛ Flow control for while loop :
It is also called as "entry control loop"
while(i>0){
System.out.println(i);
i--;
}
do-while loop
- do-while loop is used to iterate a part of the program repeatedly, until the specified condition is
true.
- We use do-while loop when the exact number of iteration is not known to us and you want to execute
the loop at least once.
- do-while loop is executed at least once even if the condition is false.
It is also called as "exit control loop"
Syntax :
Example :
int i=1;
do{
System.out.println(i);
i++;
}while(i<=10);
⇛ Flow control for do-while loop :
It is also called as "exit control loop"
do{
System.out.println(i);
i++;
}while(i<=10);
for loop
- For loop in java is used to iterate a block of code multiple times.
- We use for loop only when the exact number of iterations are fixed
- In for loop we can initialize the variable, check condition and increment/decrement value in one
line.
Syntax :
Example :
for (i=7; i>0; i--)
{
System.out.println(i);
}
⇛ Flow control for do-while loop :
{
System.out.println(i);
}