Local Business SEO

The Internet might be global in nature, but if your business is local, it makes no sense to concentrate on global reach, when your customers live in your city, or even in your neighborhood. For local businesses getting a global reach is a waste of resources. Instead, you should concentrate on the local community. You might be asking how you can do it, when the Web is global and Google doesn't classify sites according to their location. Here is how you can go local with SEO:

1  Use your location in your keywords.

The first trick is to use your location in your keywords. For example, if you are in London and you sell car insurance, your most important keyphrase should be “car insurance London” because this keyphrase contains your business and your location and will drive people who are looking for car insurance in London in particular.

2  Use your location in metatags

Metatags matter for search engines and you shouldn't miss to include your location, together with your other keywords in the metatags of the pages of your site. Of course, you must have your location in the keywords you use in the body text because otherwise it is a bit suspicious when your body text doesn't have your location as a keyword but your tags are stuffed with it.

3  Use your location in your body text

Keywords in the body text count a lot and you can't afford to skip them. If your web copy is optimized for “car insurance” only, this won't help you rank well with “car insurance London”, so make sure that your location is part of your keywords.

4  Take advantage of Google Places and Yahoo Local

Google Places and Yahoo Local are great places to submit to because they will include you in their listings for a particular location.

5  Create backlinks with your location as anchor text

It could be a bit tricky to get organic backlinks with your location as anchor text because some keywords with location don't sound very natural – for instance, “car insurance London” isn't grammatically correct and you will hardly get an organic inline link with it but you can use it in the Name field to comment on blogs. If the blog is dofollow, you will still get a backlink with anchor text that helps for SEO.

6  Get included in local search engine

Global search engines, such as Google, Bing, or Yahoo can bring you lots of traffic but depending on your location, local search engines might be the real golden mine. A local search engine could mean a search engine for the area (though it is not very likely to have regional search engines) or more likely for your country. For instance, Baidu is a great option, if you are selling on the Chinese market.

7  Get listed in local directories

In addition to local search engines, you need to try your luck with local directories, too. You might think that nobody reads directory listings but this isn't exactly so. For instance, Yellow Pages are one of the first places where people look when searching for a local vendor for a particular product.

8  Run locally-targeted ad campaigns

One of the most efficient ways to drive targeted, local traffic to your site is with the help of locally-targeted ad campaigns. PPC ads and classifieds are the two options that work best – at least for most webmasters.

9  Do occasional checks of your keywords

Occasionally checking the current search volume of your keywords is a good idea because shifts in search volumes are quite typical. Needless to say, if people don't search for “car insurance London” anymore because they have started using other search phrases and you continue to optimize for “car insurance London”, this is a waste of time and money. Also, keep an eye on the keywords your competitors use – this will give you clue which keywords work and which don't.

10  Use social media

Social media can drive more traffic to a site than search engines and for local search this is also true. Facebook, Twitter, and the other social networking sites have a great sales potential because you can promote your business for free and reach exactly the people you need. Local groups on social sites are especially valuable because the participants there are mainly from the region you are interested in.

11  Ask for reviews and testimonials

Client reviews and testimonials are a classical business instrument and these are like letters of recommendation for your business. However, as far as SEO is concerned, they could have another role. There are review sites, where you can publish such reviews and testimonials (or ask your clients to do it) and this will drive business to you. Some of these sites are Yelp and Merchant Circle but it is quite probable that there are regional or national review sites you can also post at.

12  Create separate pages for your different locations

When you have business in several locations, this makes the task a bit more difficult because you can't possibly optimize for all of them – you can't have a keyphrase such as “car insurance London, Berlin, Paris, New York”. In this case the solution is to create separate pages for your different locations. If your locations span the globe, you can also create different sites on different, country-specific domains (i.e. uk.co for GB, .de for Germany, etc.) but this is only reasonable to do, if your business is truly multinational. Otherwise, just a separate page for each of your locations will do.

These simple tips how to optimize your site for local searches are a must, if you rely on the local market. Maybe you are already doing some of them and you know what works for you and what doesn't. Anyway, if you haven't tried them all, try them now and see if this will have a positive impact on your rankings (and your business) or not.

Faith Quotes

To me faith means not worrying.

To one who has faith, no explanation is necessary. To one without faith, no explanation is possible.

Ultimately, blind faith is the only kind.

Vision looks upward and becomes faith.

We are a long time in learning that all our strength and salvation is in God.

We are twice armed if we fight with faith.

We can no more do without spirituality than we can do without food, shelter, or clothing.

What does God the Father look like? Although I've never seen Him, I believe - as with the Holy Spirit - He looks like Jesus looked on earth.

Worry is spiritual short sight. Its cure is intelligent faith.

Your faithfulness makes you trustworthy to God.

A faith is a necessity to a man. Woe to him who believes in nothing.

A man of courage is also full of faith.

All who call on God in true faith, earnestly from the heart, will certainly be heard, and will receive what they have asked and desired.

As your faith is strengthened you will find that there is no longer the need to have a sense of control, that things will flow as they will, and that you will flow with them, to your great delight and benefit.

Be a sinner and sin strongly, but more strongly have faith and rejoice in Christ.

Be faithful in small things because it is in them that your strength lies.

Doubt is a pain too lonely to know that faith is his twin brother.

Every tomorrow has two handles. We can take hold of it with the handle of anxiety or the handle of faith.

Faith and doubt both are needed - not as antagonists, but working side by side to take us around the unknown curve.

Faith and prayer are the vitamins of the soul; man cannot live in health without them.

Faith consists in believing when it is beyond the power of reason to believe.

Faith has to do with things that are not seen and hope with things that are not at hand.

Faith in oneself is the best and safest course.

Faith indeed tells what the senses do not tell, but not the contrary of what they see. It is above them and not contrary to them.

Faith is a knowledge within the heart, beyond the reach of proof.

Faith is a passionate intuition.

Faith is not belief without proof, but trust without reservation.

Faith is not contrary to reason.

Faith is not something to grasp, it is a state to grow into.

Faith is reason grown courageous.

Faith is spiritualized imagination.

Faith is taking the first step even when you don't see the whole staircase.

Faith is the bird that feels the light when the dawn is still dark.

Faith is the very first thing you should pack in a hope chest.

Faith is to believe what you do not see; the reward of this faith is to see what you believe.

Faith means belief in something concerning which doubt is theoretically possible.

Faith, to my mind, is a stiffening process, a sort of mental starch.

Faith: not wanting to know what is true.

God, our Creator, has stored within our minds and personalities, great potential strength and ability. Prayer helps us tap and develop these powers.

God... a being whose only definition is that he is beyond man's power to conceive.

Have faith in God; God has faith in you.

He who has faith has... an inward reservoir of courage, hope, confidence, calmness, and assuring trust that all will come out well - even though to the world it may appear to come out most badly.

I die the king's faithful servant, but God's first.

I have not lost faith in God. I have moments of anger and protest. Sometimes I've been closer to him for that reason.

I hold that religion and faith are two different things.

I seek a deeper truth, but I don't think I have to go to a building designated for worship to find it.

I think the greatest taboos in America are faith and failure.

If patience is worth anything, it must endure to the end of time. And a living faith will last in the midst of the blackest storm.

In faith there is enough light for those who want to believe and enough shadows to blind those who don't.

In the affairs of this world, men are saved not by faith, but by the want of it.

It is truer to say that martyrs create faith more than faith creates martyrs.

It takes vision and courage to create - it takes faith and courage to prove.

It was seldom that I attended any religious meetings, as my parents had not much faith in and were never so unfortunate as to unite themselves with any of the religious sects.

Keep the faith, don't lose your perseverance and always trust your gut extinct.

Keep your faith in God, but keep your powder dry.

Knowledge is only one half. Faith is the other.

Love, hope, fear, faith - these make humanity; These are its sign and note and character.

Man, I just feel blessed... I was in a situation where the only way I could come out of it was by putting my faith in God. No matter how good my lawyers were, no matter how much celebrity I had, everything was just stacked up against me.

My reason nourishes my faith and my faith my reason.

No matter how old we become, we can still call them 'Holy Mother' and 'Father' and put a child-like trust in them.

Nor shall derision prove powerful against those who listen to humanity or those who follow in the footsteps of divinity, for they shall live forever. Forever.

Only faith is sufficient.

Our faith comes in moments; our vice is habitual.

Put your nose into the Bible everyday. It is your spiritual food. And then share it. Make a vow not to be a lukewarm Christian.

Reason is our soul's left hand, faith her right.

Take the first step in faith. You don't have to see the whole staircase, just take the first step.

That deep emotional conviction of the presence of a superior reasoning power, which is revealed in the incomprehensible universe, forms my idea of God.

The faith that stands on authority is not faith.

The only faith that wears well and holds its color in all weathers is that which is woven of conviction and set with the sharp mordant of experience.

The power of faith will often shine forth the most when the character is naturally weak.

Lovely photo

By Mahesh biradar

Read Number from Console and Check if it is a Palindrome Number


  1. /*
  2.   Read Number from Console and Check if it is a Palindrome Number
  3.   This Java example shows how to input the number from console and
  4.   check if the number is a palindrome number or not.
  5. */
  6. import java.io.BufferedReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. public class InputPalindromeNumberExample {
  10. public static void main(String[] args) {
  11. System.out.println("Enter the number to check..");
  12. int number = 0;
  13. try
  14. {
  15. //take input from console
  16. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  17. //parse the line into int
  18. number = Integer.parseInt(br.readLine());
  19. }
  20. catch(NumberFormatException ne)
  21. {
  22. System.out.println("Invalid input: " + ne);
  23. System.exit(0);
  24. }
  25. catch(IOException ioe)
  26. {
  27. System.out.println("I/O Error: " + ioe);
  28. System.exit(0);
  29. }
  30. System.out.println("Number is " + number);
  31. int n = number;
  32. int reversedNumber = 0;
  33. int temp=0;
  34. //reverse the number
  35. while(n > 0){
  36. temp = n % 10;
  37. n = n / 10;
  38. reversedNumber = reversedNumber * 10 + temp;
  39. }
  40. /*
  41. * if the number and it's reversed number are same, the number is a
  42. * palindrome number
  43. */
  44. if(number == reversedNumber)
  45. System.out.println(number + " is a palindrome number");
  46. else
  47. System.out.println(number + " is not a palindrome number");
  48. }
  49. }
  50. /*
  51. Output of the program would be
  52. Enter the number to check..
  53. 121
  54. Number is 121
  55. 121 is a palindrome number
  56. */

prime numbers java

  1. /*
  2.   Prime Numbers Java Example
  3.   This Prime Numbers Java example shows how to generate prime numbers
  4.   between 1 and given number using for loop.
  5. */
  6. public class GeneratePrimeNumbersExample {
  7. public static void main(String[] args) {
  8. //define limit
  9. int limit = 100;
  10. System.out.println("Prime numbers between 1 and " + limit);
  11. //loop through the numbers one by one
  12. for(int i=1; i < 100; i++){
  13. boolean isPrime = true;
  14. //check to see if the number is prime
  15. for(int j=2; j < i ; j++){
  16. if(i % j == 0){
  17. isPrime = false;
  18. break;
  19. }
  20. }
  21. // print the number
  22. if(isPrime)
  23. System.out.print(i + " ");
  24. }
  25. }
  26. }
  27. /*
  28. Output of Prime Numbers example would be
  29. Prime numbers between 1 and 100
  30. 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
  31. */




list Odd numbers java

  1. /*

  2. List Odd Numbers Java Example

  3. This List Odd Numbers Java Example shows how to find and list odd

  4. numbers between 1 and any given number.

  5. */

  6.  

  7. public class ListOddNumbers {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. //define the limit

  12. int limit = 50;

  13.  

  14. System.out.println("Printing Odd numbers between 1 and " + limit);

  15.  

  16. for(int i=1; i <= limit; i++){

  17.  

  18. //if the number is not divisible by 2 then it is odd

  19. if( i % 2 != 0){

  20. System.out.print(i + " ");

  21. }

  22. }

  23. }

  24. }

  25.  

  26. /*

  27. Output of List Odd Numbers Java Example would be

  28. Printing Odd numbers between 1 and 50

  29. 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49

  30. */



List Even Numbers Java

  1. /*

  2. List Even Numbers Java Example

  3. This List Even Numbers Java Example shows how to find and list even

  4. numbers between 1 and any given number.

  5. */

  6.  

  7. public class ListEvenNumbers {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. //define limit

  12. int limit = 50;

  13.  

  14. System.out.println("Printing Even numbers between 1 and " + limit);

  15.  

  16. for(int i=1; i <= limit; i++){

  17.  

  18. // if the number is divisible by 2 then it is even

  19. if( i % 2 == 0){

  20. System.out.print(i + " ");

  21. }

  22. }

  23. }

  24. }

  25.  

  26. /*

  27. Output of List Even Numbers Java Example would be

  28. Printing Even numbers between 1 and 50

  29. 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50

  30. */

Java Pyramid

  1. /*

  2. Java Pyramid Example

  3. This Java Pyramid example shows how to generate pyramid or triangle like

  4. given below using for loop.

  5.  

  6. *

  7. **

  8. ***

  9. ****

  10. *****

  11. */

  12.  

  13. public class JavaPyramid1 {

  14.  

  15. public static void main(String[] args) {

  16.  

  17. for(int i=1; i<= 5 ;i++){

  18.  

  19. for(int j=0; j < i; j++){

  20. System.out.print("*");

  21. }

  22.  

  23. //generate a new line

  24. System.out.println("");

  25. }

  26. }

  27. }

  28.  

  29. /*

  30. Output of the above program would be

  31. *

  32. **

  33. ***

  34. ****

  35. *****

  36. */

Java Palindrome Number

  1. /*

  2. Java Palindrome Number Example

  3. This Java Palindrome Number Example shows how to find if the given

  4. number is palindrome number or not.

  5. */

  6.  

  7.  

  8. public class JavaPalindromeNumberExample {

  9.  

  10. public static void main(String[] args) {

  11.  

  12. //array of numbers to be checked

  13. int numbers[] = new int[]{121,13,34,11,22,54};

  14.  

  15. //iterate through the numbers

  16. for(int i=0; i < numbers.length; i++){

  17.  

  18. int number = numbers[i];

  19. int reversedNumber = 0;

  20. int temp=0;

  21.  

  22. /*

  23. * If the number is equal to it's reversed number, then

  24. * the given number is a palindrome number.

  25. *

  26. * For example, 121 is a palindrome number while 12 is not.

  27. */

  28.  

  29. //reverse the number

  30. while(number > 0){

  31. temp = number % 10;

  32. number = number / 10;

  33. reversedNumber = reversedNumber * 10 + temp;

  34. }

  35.  

  36. if(numbers[i] == reversedNumber)

  37. System.out.println(numbers[i] + " is a palindrome number");

  38. else

  39. System.out.println(numbers[i] + " is not a palindrome number");

  40. }

  41.  

  42. }

  43. }

  44.  

  45. /*

  46. Output of Java Palindrome Number Example would be

  47. 121 is a palindrome number

  48. 13 is not a palindrome number

  49. 34 is not a palindrome number

  50. 11 is a palindrome number

  51. 22 is a palindrome number

  52. 54 is not a palindrome number

  53. */

Infinite For loop

  1. /*

  2.   Infinite For loop Example

  3.   This Java Example shows how to create a for loop that runs infinite times

  4.   in Java program. It happens when the loop condition is always evaluated as true.

  5. */

  6.  

  7. public class InfiniteForLoop {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. /*

  12.   * Its perfectely legal to skip any of the 3 parts of the for loop.

  13.   * Below given for loop will run infinite times.

  14.   */

  15. for(;;)

  16. System.out.println("Hello");

  17.  

  18. /*

  19.   * To terminate this program press ctrl + c in the console.

  20.   */

  21. }

  22. }

  23.  

  24. /*

  25. Output would be

  26. Hello

  27. Hello

  28. Hello

  29. Hello

  30. ..

  31. ..

  32. */

Generate Pyramid For a Given Number

  1. /*

  2. Generate Pyramid For a Given Number Example

  3. This Java example shows how to generate a pyramid of numbers for given

  4. number using for loop example.

  5. */

  6.  

  7. import java.io.BufferedReader;

  8. import java.io.InputStreamReader;

  9.  

  10. public class GeneratePyramidExample {

  11.  

  12. public static void main (String[] args) throws Exception{

  13.  

  14. BufferedReader keyboard = new BufferedReader (new InputStreamReader (System.in));

  15.  

  16. System.out.println("Enter Number:");

  17. int as= Integer.parseInt (keyboard.readLine());

  18. System.out.println("Enter X:");

  19. int x= Integer.parseInt (keyboard.readLine());

  20.  

  21. int y = 0;

  22.  

  23. for(int i=0; i<= as ;i++){

  24.  

  25. for(int j=1; j <= i ; j++){

  26. System.out.print(y + "\t");

  27. y = y + x;

  28. }

  29.  

  30. System.out.println("");

  31. }

  32. }

  33. }

  34.  

  35. /*

  36. Output of this example would be

  37.  

  38. Enter Number:

  39. 5

  40. Enter X:

  41. 1

  42.  

  43. 0

  44. 1 2

  45. 3 4 5

  46. 6 7 8 9

  47. 10 11 12 13 14

  48.  

  49. ----------------------------------------------

  50.  

  51. Enter Number:

  52. 5

  53. Enter X:

  54. 2

  55.  

  56. 0

  57. 2 4

  58. 6 8 10

  59. 12 14 16 18

  60. 20 22 24 26 28

  61.  

  62. ----------------------------------------------

  63.  

  64. Enter Number:

  65. 5

  66. Enter X:

  67. 3

  68.  

  69. 0

  70. 3 6

  71. 9 12 15

  72. 18 21 24 27

  73. 30 33 36 39 42

  74. */

Fibonacci Series Java

  1. /*

  2. Fibonacci Series Java Example

  3. This Fibonacci Series Java Example shows how to create and print

  4. Fibonacci Series using Java.

  5. */

  6.  

  7. public class JavaFibonacciSeriesExample {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. //number of elements to generate in a series

  12. int limit = 20;

  13.  

  14. long[] series = new long[limit];

  15.  

  16. //create first 2 series elements

  17. series[0] = 0;

  18. series[1] = 1;

  19.  

  20. //create the Fibonacci series and store it in an array

  21. for(int i=2; i < limit; i++){

  22. series[i] = series[i-1] + series[i-2];

  23. }

  24.  

  25. //print the Fibonacci series numbers

  26.  

  27. System.out.println("Fibonacci Series upto " + limit);

  28. for(int i=0; i< limit; i++){

  29. System.out.print(series[i] + " ");

  30. }

  31. }

  32. }

  33.  

  34. /*

  35. Output of the Fibonacci Series Java Example would be

  36. Fibonacci Series upto 20

  37. 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

  38. */

multiple variables in for loop

  1. /*

  2.   Declare multiple variables in for loop Example

  3.   This Java Example shows how to declare multiple variables in Java For loop using

  4.   declaration block.

  5. */

  6.  

  7. public class DeclaringMultipleVariablesInForLoopExample {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. /*

  12.   * Multiple variables can be declared in declaration block of for loop.

  13.   */

  14.  

  15. for(int i=0, j=1, k=2 ; i<5 ; i++)

  16. System.out.println("I : " + i + ",j : "+ j + ", k : " + k);

  17.  

  18. /*

  19.   * Please note that the variables which are declared, should be of same type

  20.   * as in this example int.

  21.   */

  22.  

  23. //THIS WILL NOT COMPILE

  24. //for(int i=0, float j; i < 5; i++);

  25. }

  26. }

multiple variables in for loop

  1. /*

  2.   Declare multiple variables in for loop Example

  3.   This Java Example shows how to declare multiple variables in Java For loop using

  4.   declaration block.

  5. */

  6.  

  7. public class DeclaringMultipleVariablesInForLoopExample {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. /*

  12.   * Multiple variables can be declared in declaration block of for loop.

  13.   */

  14.  

  15. for(int i=0, j=1, k=2 ; i<5 ; i++)

  16. System.out.println("I : " + i + ",j : "+ j + ", k : " + k);

  17.  

  18. /*

  19.   * Please note that the variables which are declared, should be of same type

  20.   * as in this example int.

  21.   */

  22.  

  23. //THIS WILL NOT COMPILE

  24. //for(int i=0, float j; i < 5; i++);

  25. }

  26. }

Calculate Average value of Array elements using Java

  1. /*

  2. Calculate Average value of Array elements using Java Example

  3. This Java Example shows how to calculate average value of array

  4. elements.

  5. */

  6. public class CalculateArrayAverageExample {

  7.  

  8. public static void main(String[] args) {

  9.  

  10. //define an array

  11. int[] numbers = new int[]{10,20,15,25,16,60,100};

  12.  

  13. /*

  14. * Average value of array elements would be

  15. * sum of all elements/total number of elements

  16. */

  17.  

  18. //calculate sum of all array elements

  19. int sum = 0;

  20.  

  21. for(int i=0; i < numbers.length ; i++)

  22. sum = sum + numbers[i];

  23.  

  24. //calculate average value

  25. double average = sum / numbers.length;

  26.  

  27. System.out.println("Average value of array elements is : " + average);

  28. }

  29. }

  30.  

  31. /*

  32. Output of Calculate Average value of Array elements using Java Example would be

  33. Average value of array elements is : 35.0

  34. */

Java break statement

  1. /*

  2.   Java break statement example.

  3.   This example shows how to use java break statement to terminate the loop.

  4. */

  5. public class JavaBreakExample {

  6.  

  7. public static void main(String[] args) {

  8. /*

  9.   * break statement is used to terminate the loop in java. The following example

  10.   * breaks the loop if the array element is equal to true.

  11.   *

  12.   * After break statement is executed, the control goes to the statement

  13.   * immediately after the loop containing break statement.

  14.   */

  15.  

  16. int intArray[] = new int[]{1,2,3,4,5};

  17.  

  18. System.out.println("Elements less than 3 are : ");

  19. for(int i=0; i < intArray.length ; i ++)

  20. {

  21. if(intArray[i] == 3)

  22. break;

  23. else

  24. System.out.println(intArray[i]);

  25. }

  26.  

  27. }

  28. }

  29.  

  30. /*

  31. Output would be

  32. Elements less than 3 are :

  33. 1

  34. 2

  35. */

Java break statement with label

  1. /*

  2.   Java break statement with label example.

  3.   This example shows how to use java break statement to terminate the labeled loop.

  4.   The following example uses break to terminate the labeled loop while searching two

  5.   dimensional int array.

  6. */

  7.  

  8. public class JavaBreakWithLableExample {

  9.  

  10. public static void main(String[] args) {

  11.  

  12.  

  13. int[][] intArray = new int[][]{{1,2,3,4,5},{10,20,30,40,50}};

  14. boolean blnFound = false;

  15.  

  16. System.out.println("Searching 30 in two dimensional int array..");

  17.  

  18. Outer:

  19. for(int intOuter=0; intOuter < intArray.length ; intOuter++)

  20. {

  21. Inner:

  22. for(int intInner=0; intInner < intArray[intOuter].length; intInner++)

  23. {

  24. if(intArray[intOuter][intInner] == 30)

  25. {

  26. blnFound = true;

  27. break Outer;

  28. }

  29.  

  30. }

  31. }

  32.  

  33. if(blnFound == true)

  34. System.out.println("30 found in the array");

  35. else

  36. System.out.println("30 not found in the array");

  37. }

  38. }

  39.  

  40. /*

  41. Output would be

  42. Searching 30 in two dimensional int array..

  43. 30 found in the array

  44. */

Swap Numbers Without Using Third Variable

  1. /*

  2. Swap Numbers Without Using Third Variable Java Example

  3. This Swap Numbers Java Example shows how to

  4. swap value of two numbers without using third variable using java.

  5. */

  6.  

  7. public class SwapElementsWithoutThirdVariableExample {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. int num1 = 10;

  12. int num2 = 20;

  13.  

  14. System.out.println("Before Swapping");

  15. System.out.println("Value of num1 is :" + num1);

  16. System.out.println("Value of num2 is :" +num2);

  17.  

  18. //add both the numbers and assign it to first

  19. num1 = num1 + num2;

  20. num2 = num1 - num2;

  21. num1 = num1 - num2;

  22.  

  23. System.out.println("Before Swapping");

  24. System.out.println("Value of num1 is :" + num1);

  25. System.out.println("Value of num2 is :" +num2);

  26. }

  27.  

  28.  

  29. }

  30.  

  31. /*

  32. Output of Swap Numbers Without Using Third Variable example would be

  33. Before Swapping

  34. Value of num1 is :10

  35. Value of num2 is :20

  36. Before Swapping

  37. Value of num1 is :20

  38. Value of num2 is :10

  39. */

Swap Numbers Java Example

  1. /*

  2. Swap Numbers Java Example

  3. This Swap Numbers Java Example shows how to

  4. swap value of two numbers using java.

  5. */

  6.  

  7. public class SwapElementsExample {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. int num1 = 10;

  12. int num2 = 20;

  13.  

  14. System.out.println("Before Swapping");

  15. System.out.println("Value of num1 is :" + num1);

  16. System.out.println("Value of num2 is :" +num2);

  17.  

  18. //swap the value

  19. swap(num1, num2);

  20. }

  21.  

  22. private static void swap(int num1, int num2) {

  23.  

  24. int temp = num1;

  25. num1 = num2;

  26. num2 = temp;

  27.  

  28. System.out.println("After Swapping");

  29. System.out.println("Value of num1 is :" + num1);

  30. System.out.println("Value of num2 is :" +num2);

  31.  

  32. }

  33. }

  34.  

  35. /*

  36. Output of Swap Numbers example would be

  37. Before Swapping

  38. Value of num1 is :10

  39. Value of num2 is :20

  40. After Swapping

  41. Value of num1 is :20

  42. Value of num2 is :10

  43. */

Reverse Number using Java

  1. /*

  2.   Reverse Number using Java

  3.   This Java Reverse Number Example shows how to reverse a given number.

  4. */

  5.  

  6. public class ReverseNumber {

  7.  

  8. public static void main(String[] args) {

  9.  

  10. //original number

  11. int number = 1234;

  12. int reversedNumber = 0;

  13. int temp = 0;

  14.  

  15. while(number > 0){

  16.  

  17. //use modulus operator to strip off the last digit

  18. temp = number%10;

  19.  

  20. //create the reversed number

  21. reversedNumber = reversedNumber * 10 + temp;

  22. number = number/10;

  23.  

  24. }

  25.  

  26. //output the reversed number

  27. System.out.println("Reversed Number is: " + reversedNumber);

  28. }

  29. }

  30.  

  31. /*

  32. Output of this Number Reverse program would be

  33. Reversed Number is: 4321

  34. */

Java Interface example

  1. /*

  2. Java Interface example.

  3. This Java Interface example describes how interface is defined and

  4. being used in Java language.

  5.  

  6. Syntax of defining java interface is,

  7. <modifier> interface <interface-name>{

  8.   //members and methods()

  9. }

  10. */

  11.  

  12. //declare an interface

  13. interface IntExample{

  14.  

  15. /*

  16.   Syntax to declare method in java interface is,

  17.   <modifier> <return-type> methodName(<optional-parameters>);

  18.   IMPORTANT : Methods declared in the interface are implicitly public and abstract.

  19.   */

  20.  

  21. public void sayHello();

  22. }

  23. }

  24. /*

  25. Classes are extended while interfaces are implemented.

  26. To implement an interface use implements keyword.

  27. IMPORTANT : A class can extend only one other class, while it

  28. can implement n number of interfaces.

  29. */

  30.  

  31. public class JavaInterfaceExample implements IntExample{

  32. /*

  33.   We have to define the method declared in implemented interface,

  34.   or else we have to declare the implementing class as abstract class.

  35.   */

  36.  

  37. public void sayHello(){

  38. System.out.println("Hello Visitor !");

  39. }

  40.  

  41. public static void main(String args[]){

  42. //create object of the class

  43. JavaInterfaceExample javaInterfaceExample = new JavaInterfaceExample();

  44. //invoke sayHello(), declared in IntExample interface.

  45. javaInterfaceExample.sayHello();

  46. }

  47. }

  48.  

  49. /*

  50. OUTPUT of the above given Java Interface example would be :

  51. Hello Visitor !

  52. */

Java Factorial Using Recursion

  1. /*

  2. Java Factorial Using Recursion Example

  3. This Java example shows how to generate factorial of a given number

  4. using recursive function.

  5. */

  6.  

  7. import java.io.BufferedReader;

  8. import java.io.IOException;

  9. import java.io.InputStreamReader;

  10.  

  11. public class JavaFactorialUsingRecursion {

  12.  

  13. public static void main(String args[]) throws NumberFormatException, IOException{

  14.  

  15. System.out.println("Enter the number: ");

  16.  

  17. //get input from the user

  18. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

  19. int a = Integer.parseInt(br.readLine());

  20.  

  21. //call the recursive function to generate factorial

  22. int result= fact(a);

  23.  

  24.  

  25. System.out.println("Factorial of the number is: " + result);

  26. }

  27.  

  28. static int fact(int b)

  29. {

  30. if(b <= 1)

  31. //if the number is 1 then return 1

  32. return 1;

  33. else

  34. //else call the same function with the value - 1

  35. return b * fact(b-1);

  36. }

  37. }

  38.  

  39. /*

  40. Output of this Java example would be

  41.  

  42. Enter the number:

  43. 5

  44. Factorial of the number is: 120

  45. */

Java Factorial Example

  1. /*

  2.   Java Factorial Example

  3.   This Java Factorial Example shows how to calculate factorial of

  4.   a given number using Java.

  5. */

  6.  

  7. public class NumberFactorial {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. int number = 5;

  12.  

  13. /*

  14. * Factorial of any number is !n.

  15. * For example, factorial of 4 is 4*3*2*1.

  16. */

  17.  

  18. int factorial = number;

  19.  

  20. for(int i =(number - 1); i > 1; i--)

  21. {

  22. factorial = factorial * i;

  23. }

  24.  

  25. System.out.println("Factorial of a number is " + factorial);

  26. }

  27. }

  28.  

  29. /*

  30. Output of the Factorial program would be

  31. Factorial of a number is 120

  32. */

Java Class example

  1. /*

  2. Java Class example.

  3. This Java class example describes how class is defined and being used

  4. in Java language.

  5.  

  6. Syntax of defining java class is,

  7. <modifier> class <class-name>{

  8.   // members and methods

  9. }

  10. */

  11.  

  12. public class JavaClassExample{

  13. /*

  14.   Syntax of defining memebers of the java class is,

  15.   <modifier> type <name>;

  16.   */

  17. private String name;

  18. /*

  19.   Syntax of defining methods of the java class is,

  20.   <modifier> <return-type> methodName(<optional-parameter-list>) <exception-list>{

  21.   ...

  22.   }

  23.   */

  24. public void setName(String n){

  25. //set passed parameter as name

  26. name = n;

  27. }

  28. public String getName(){

  29. //return the set name

  30. return name;

  31. }

  32. //main method will be called first when program is executed

  33. public static void main(String args[]){

  34. /*

  35.   Syntax of java object creation is,

  36.   <class-name> object-name = new <class-constructor>;

  37.   */

  38. JavaClassExample javaClassExample = new JavaClassExample();

  39. //set name member of this object

  40. javaClassExample.setName("Visitor");

  41. // print the name

  42. System.out.println("Hello " + javaClassExample.getName());

  43. }

  44. }

  45.  

  46. /*

  47. OUTPUT of the above given Java Class Example would be :

  48. Hello Visitor

  49. */

Hello World java

  1. /*

  2. Java Hello World example.

  3. */

  4.  

  5. public class HelloWorldExample{

  6.  

  7. public static void main(String args[]){

  8.  

  9. /*

  10.   Use System.out.println() to print on console.

  11.   */

  12. System.out.println("Hello World !");

  13.  

  14. }

  15.  

  16. }

  17.  

  18. /*

  19.  

  20. OUTPUT of the above given Java Hello World Example would be :

  21.  

  22. Hello World !

  23.  

  24. */

Find Largest and Smallest Number in an Array

  1. /*

  2.   Find Largest and Smallest Number in an Array Example

  3.   This Java Example shows how to find largest and smallest number in an

  4.   array.

  5. */

  6. public class FindLargestSmallestNumber {

  7.  

  8. public static void main(String[] args) {

  9.  

  10. //array of 10 numbers

  11. int numbers[] = new int[]{32,43,53,54,32,65,63,98,43,23};

  12.  

  13. //assign first element of an array to largest and smallest

  14. int smallest = numbers[0];

  15. int largetst = numbers[0];

  16.  

  17. for(int i=1; i< numbers.length; i++)

  18. {

  19. if(numbers[i] > largetst)

  20. largetst = numbers[i];

  21. else if (numbers[i] < smallest)

  22. smallest = numbers[i];

  23.  

  24. }

  25.  

  26. System.out.println("Largest Number is : " + largetst);

  27. System.out.println("Smallest Number is : " + smallest);

  28. }

  29. }

  30.  

  31. /*

  32. Output of this program would be

  33. Largest Number is : 98

  34. Smallest Number is : 23

  35. */

Odd Number Java

  1. /*

  2.   Even Odd Number Example

  3.   This Java Even Odd Number Example shows how to check if the given

  4.   number is even or odd.

  5. */

  6.  

  7. public class FindEvenOrOddNumber {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. //create an array of 10 numbers

  12. int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};

  13.  

  14. for(int i=0; i < numbers.length; i++){

  15.  

  16. /*

  17. * use modulus operator to check if the number is even or odd.

  18. * If we divide any number by 2 and reminder is 0 then the number is

  19. * even, otherwise it is odd.

  20. */

  21.  

  22. if(numbers[i]%2 == 0)

  23. System.out.println(numbers[i] + " is even number.");

  24. else

  25. System.out.println(numbers[i] + " is odd number.");

  26.  

  27. }

  28.  

  29. }

  30. }

  31.  

  32. /*

  33. Output of the program would be

  34. 1 is odd number.

  35. 2 is even number.

  36. 3 is odd number.

  37. 4 is even number.

  38. 5 is odd number.

  39. 6 is even number.

  40. 7 is odd number.

  41. 8 is even number.

  42. 9 is odd number.

  43. 10 is even number.

  44. */

Calculate Rectangle Perimeter using Java

  1. /*

  2. Calculate Rectangle Perimeter using Java Example

  3. This Calculate Rectangle Perimeter using Java Example shows how to calculate

  4. perimeter of Rectangle using it's length and width.

  5. */

  6.  

  7. import java.io.BufferedReader;

  8. import java.io.IOException;

  9. import java.io.InputStreamReader;

  10.  

  11. public class CalculateRectPerimeter {

  12.  

  13. public static void main(String[] args) {

  14.  

  15. int width = 0;

  16. int length = 0;

  17.  

  18. try

  19. {

  20. //read the length from console

  21. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

  22.  

  23. System.out.println("Please enter length of a rectangle");

  24. length = Integer.parseInt(br.readLine());

  25.  

  26. //read the width from console

  27. System.out.println("Please enter width of a rectangle");

  28. width = Integer.parseInt(br.readLine());

  29.  

  30.  

  31. }

  32. //if invalid value was entered

  33. catch(NumberFormatException ne)

  34. {

  35. System.out.println("Invalid value" + ne);

  36. System.exit(0);

  37. }

  38. catch(IOException ioe)

  39. {

  40. System.out.println("IO Error :" + ioe);

  41. System.exit(0);

  42. }

  43.  

  44. /*

  45. * Perimeter of a rectangle is

  46. * 2 * (length + width)

  47. */

  48.  

  49. int perimeter = 2 * (length + width);

  50.  

  51. System.out.println("Perimeter of a rectangle is " + perimeter);

  52. }

  53.  

  54. }

  55.  

  56. /*

  57. Output of Calculate Rectangle Perimeter using Java Example would be

  58. Please enter length of a rectangle

  59. 10

  60. Please enter width of a rectangle

  61. 15

  62. Perimeter of a rectangle is 50

  63. */

Calculate Rectangle Area using Java

  1. /*

  2. Calculate Rectangle Area using Java Example

  3. This Calculate Rectangle Area using Java Example shows how to calculate

  4. area of Rectangle using it's length and width.

  5. */

  6.  

  7. import java.io.BufferedReader;

  8. import java.io.IOException;

  9. import java.io.InputStreamReader;

  10.  

  11. public class CalculateRectArea {

  12.  

  13. public static void main(String[] args) {

  14.  

  15. int width = 0;

  16. int length = 0;

  17.  

  18. try

  19. {

  20. //read the length from console

  21. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

  22.  

  23. System.out.println("Please enter length of a rectangle");

  24. length = Integer.parseInt(br.readLine());

  25.  

  26. //read the width from console

  27. System.out.println("Please enter width of a rectangle");

  28. width = Integer.parseInt(br.readLine());

  29.  

  30.  

  31. }

  32. //if invalid value was entered

  33. catch(NumberFormatException ne)

  34. {

  35. System.out.println("Invalid value" + ne);

  36. System.exit(0);

  37. }

  38. catch(IOException ioe)

  39. {

  40. System.out.println("IO Error :" + ioe);

  41. System.exit(0);

  42. }

  43.  

  44. /*

  45. * Area of a rectangle is

  46. * length * width

  47. */

  48.  

  49. int area = length * width;

  50.  

  51. System.out.println("Area of a rectangle is " + area);

  52. }

  53.  

  54. }

  55.  

  56. /*

  57. Output of Calculate Rectangle Area using Java Example would be

  58. Please enter length of a rectangle

  59. 10

  60. Please enter width of a rectangle

  61. 15

  62. Area of a rectangle is 150

  63. */

Calculate Circle Perimeter using Java

  1. /*

  2. Calculate Circle Perimeter using Java Example

  3. This Calculate Circle Perimeter using Java Example shows how to calculate

  4. Perimeter of circle using it's radius.

  5. */

  6.  

  7. import java.io.BufferedReader;

  8. import java.io.IOException;

  9. import java.io.InputStreamReader;

  10.  

  11. public class CalculateCirclePerimeterExample {

  12.  

  13. public static void main(String[] args) {

  14.  

  15. int radius = 0;

  16. System.out.println("Please enter radius of a circle");

  17.  

  18. try

  19. {

  20. //get the radius from console

  21. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

  22. radius = Integer.parseInt(br.readLine());

  23. }

  24. //if invalid value was entered

  25. catch(NumberFormatException ne)

  26. {

  27. System.out.println("Invalid radius value" + ne);

  28. System.exit(0);

  29. }

  30. catch(IOException ioe)

  31. {

  32. System.out.println("IO Error :" + ioe);

  33. System.exit(0);

  34. }

  35.  

  36. /*

  37. * Perimeter of a circle is

  38. * 2 * pi * r

  39. * where r is a radius of a circle.

  40. */

  41.  

  42. //NOTE : use Math.PI constant to get value of pi

  43. double perimeter = 2 * Math.PI * radius;

  44.  

  45. System.out.println("Perimeter of a circle is " + perimeter);

  46. }

  47. }

  48.  

  49. /*

  50. Output of Calculate Circle Perimeter using Java Example would be

  51. Please enter radius of a circle

  52. 19

  53. Perimeter of a circle is 119.38052083641213

  54. */