Pages

Sunday, December 26, 2021

 Concept

    To test more than one condition, an if statement can be nested inside another if statement.

Syntax

if(BooleanExpression 1) {
   // Executes when the Boolean expression 1 is true
   if(BooleanExpression 2) {
      // Executes when the Boolean expression 2 is true
   }
}

Logic




How nested if works?

If the expression 1 is true, however, we need to test the second condition. If the expression 2 is true, 
we need to test the third condition and so on. The statements within the true block will get executed.
And then the execution continues with the next statements following the if.

Example (Test.java)

public class Test {

   public static void main(String args[]) {
      int x = 30;
      int y = 10;

      if( x == 30 ) {
         if( y == 10 ) {
            System.out.print("X = 30 and Y = 10");
         }
      }
   }
}

Output

X = 30 and Y = 10

Saturday, December 25, 2021

Decision Statements - if-else statement

Concept

The if-else statement will execute one group of statements if its boolean expression is true, or another group if its boolean expression is false.

Syntax

Here is the general format:

if (BooleanExpression)
statement or block
else
statement or block

Logic


How if-else statement works?

Like the if statement, a boolean expression is evaluated. If the expression is true, a statement or block of statements is executed. If the expression is false, however, statements within else part is executed.

Example (IfElseDemo.java)

class IfElseDemo {
    public static void main(String args[])
    {
        int i = 20;
  
        if (i < 15)
            System.out.println("i is smaller than 15");
        else
            System.out.println("i is greater than 15");
  
        System.out.println("Outside if-else block");
    }
}

Output
i is greater than 15
Outside if-else block


Decision Statements - if

Concept 

The if statement is used to create a decision structure, which allows a program to have more than one path of execution. The if statement causes one or more statements to execute only when a boolean expression is true.

Syntax

Here is the general format of the if statement:

    if (BooleanExpression)
    statement;

Logic



How if statement works?

The if condition that appears inside the parentheses must be a boolean expression. A boolean expression may be either true or false. If it is true, the very next statement is executed. Otherwise, it is skipped. The statement is conditionally executed because it executes only under the condition that the expression in the parentheses is true.


Example (IfDemo.java)

class IfDemo {
    public static void main(String args[])
    {
        int i = 10;
  
        if (i < 15)
            System.out.println("10 is less than 15");
  
            System.out.println("Outside if-block");
    }
}

Output
10 is less than 15
Outside if-block




Friday, December 24, 2021

Loop Statements

 A loop is a control structure that causes a statement or group of statements to repeat.

Java supports three looping structures:

  • while
  • do...while
  • for
While Loop

The while statement has two parts:

  1. a boolean expression (tests whether the condition is true or false)
  2. a statement or block of statements that is repeated until the condition is true
    Syntax

    Here is the general format of the while loop:
        
        while (BooleanExpression)
        Statement;

    Logic














How while loop works?

The Boolean Expression is tested, and if it is true, the Statement is executed. Then, the Boolean Expression is tested again. If it is true, the Statement is executed. This cycle repeats until the Boolean Expression is false.

Example (WhileLoop.java)

public class WhileLoop
{
public static void main(String[] args)
{
int number = 1;
    while (number <= 5)
     {
     System.out.println("Hello");
     number++;
     }
System.out.println("That's all!");
}
}

Output

Hello
Hello
Hello
Hello
Hello
That's all!



Sunday, July 4, 2010

Seven wonders of the world
















Taj Mahal.......
















Christ Redeemer, Brasil.............

















Colosseum, Italy........

















Machu picchu, Peru.....

















The great wall of china........















Chichen Itza, Mexico.....























Petra, Jordan....