Control Statements In Java
Control statements are the statements which alter the flow of execution. The following control statements are available in java:
- if else statement
- do while loop
- while loop
- for loop
- for each loop
- switch statement
- break statement
- continue statement
if else Statement
Syntax
if(condition)
statement 1 ;
[else statement 2;]
Program 1
Write a program to test if a number is positive or negative.
Program 2
Write a program to find the largest of two numbers
Program 3
Write a program to find even or odd
Program 4
Write a program to find the leap year
Program 5
Write a program to display examination result
do while Loop
Syntax
do {
statements;
}
while (condition);
Program
Write a program to display numbers from 1 to 10
while Loop
Syntax
while(condition)
{
statements;
}
Program 1
Write a program to display 1 to 20
Program 2
Write a program to find the reverse of a number
Program 3
Write a program to find the sum of digits
Program 4
Write a program to find the palindrome
for Loop
Syntax
for( expression1; expression2; expression3)
{
statements;
}
Program 1
Write a program to find the factorial of a number
Syntax
for( expression1; expression2; expression3)
{
statements;
}
Program 1
Write a program to find the factorial of a number
program 2
Write a program to calculate the sum of squares of n even numbers
Program 3
write a program to display multiplication table of a number
Program 4
write a program to display the cube of a number
Nested for Loops
We can write a for loop within another for loop. Such loops are called nested for loops.
Problem 1
Write a program to print the following pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program 2
Print the following pattern using for loop
* * * * *
* * * * *
* * * * *
Next Tutorial about :
(Click on the link below)
Anu k Joy
Write a program to calculate the sum of squares of n even numbers
Program 3
write a program to display multiplication table of a number
Program 4
write a program to display the cube of a number
Nested for Loops
We can write a for loop within another for loop. Such loops are called nested for loops.
Problem 1
Write a program to print the following pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program 2
Print the following pattern using for loop
* * * * *
* * * * *
* * * * *
Next Tutorial about :
(Click on the link below)
Accepting input outputs from the keyboard
Previous Blogs:
















No comments:
Post a Comment