OOP Unit-I Java Introduction -3
OOP Unit-I Java Introduction -3
Oriented Programming
UNIT - I
Prepared by,
Mrs. T. SUGANYA,
M.E.,
JAVA
Topics
Iteration Statements
Jump Statements
Simple java program execution
Fundamental Programming
Structures
8. Control Statement
Used to change the sequential
flow of execution
Looping/Iteration statements are
used to execute a set of statements
repeatedly until some condition holds
true.
Types
for loop
while loop
do while loop
For loop
for ( initialization ; condition;
increment/decrement)
statement;
• Control Variable is used to control the no. of
repetitions
• Initialize the control variable i=1
• Condition i<=10
• Increment or decrement the control variable
i++
Valid for
for(i=1,j=1;i<=6;i++,j++)
for(;i<=10;)
For Statement
class iteration
{
public static void main(String args[])
{
int i; Number
System.out.println(“Numbers”); s
i=1
for( i=1;i<=5;i++) i=2
{ i=3
i=4
System.out.println(“i=”+i);
i=5
} Over
System.out.println(“Over”);
}
while loop
initialization ;
while(condition)
{
Body of the loop;
increment/decrement;
}
Method Description
nextBoolea Reads a boolean value from the user
n()
nextByte() Reads a byte value from the user
nextDouble Reads a double value from the user
()
nextFloat() Reads a float value from the user
nextInt() Reads a int value from the user
nextLine() Reads a String value from the user
nextLong() Reads a long value from the user
nextShort() Reads a short value from the user
Enter any number: 101
Output: The number entered by user:
101
import java.util.Scanner; // Import the
Scanner class
class MyClass {
public static void main(String[] args)
{
// Create a Scanner object
Scanner myObj = new Scanner(System.in);
System.out.println("Enter username");