Sep 18 2009

If & Else if

Category: C Programmingadmin @ 11:07 pm

/*represent the if,else if */
#include<stdio.h>
main()
{
      int age1,age2;
      printf("Enter your age:");
      scanf("%d",&age1);
      printf("Your age is %d\n",age1);
      age2=30;
      printf("My age is %d\n",age2);
 
      if (age1>age2)
      {
        printf("I'm younger Than You :D\n");
        printf("You are %d years elder than me",age1-age2);
      } 
      else if(age1==age2)
        printf("We are in same age"); 
 
      else
        printf("I'm elder Than You");
 
       fflush(stdin);
       getchar();
}

Tags: , , ,


Jul 17 2009

Flow Statements-If & Switch

Category: Javaadmin @ 10:31 pm

  • If
public class flow1
{
	public static void main(String[] args)
	{
	int x=15;
	if (x&gt;10)
		{
			System.out.println("x is grater than 10 ");
			System.out.println(x&gt;10);
		}
	else
		{
			System.out.println("x is not grater than 10");
			System.out.println(x&gt;10);
		}
	}
 
}

Result
x is grater than 10
true

  • Switch
public class flow2
{
		public static void main(String[] args)
		{
			int x=2;
			switch (x)
			{
				case 1:
					System.out.println("You have selected num 1");
					break;
				case 2:
					System.out.println("You have selected num 2");
					break;
				case 6:
					System.out.println("You have selected num 6");
					break;
				default:
					System.out.println("You haven't selected any num");
 
			}
 
		}
}

Result

You have selected num 2

Tags: , , , ,