Simple Programs

  1. Program to swap two numbers
  2. Program to reverse a 3 digit number
  3. Program to find sum of first and last digit of a number
  4. Program to find sum of all digits of a number
  5. Program for cash denomination

Use of loops like

  1. if-else loop
  2. ladder if-else
  3. nested if-else

Introduction about armstrong and palindrome numbers.

1. WAP to Swap 2 numbers.

Class add

{ public static void main(String [] args)

int a,b,c;

a=3;

b=8;

a=b;

b=c;

c=a;

System.out.print(a);

System.out,print(b);

}

 

2.WAP to Swap 2 no.s using third variable.

Class add

{ public static void main(String [] args)

int a,b,c;

a=3;

b=8;

a=a+b;

b=a-b;

a=a-b;

System.out.print(a);

System.out,print(b);

}

 

3.WAP to reverse a 3-digit no.

Class add2

{ public static void main(String [] args)

int a,b=0;

a=321;

while(a!=0)

{

b=b*10;

b=b*10+a%10;

a=a/10;

System.out.print(“the reversed no. is : “+a”);

}

Advertisements

Constructive and genuine appreciation and/or criticism most welcome

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s