Pages

Ads 468x60px

Featured Posts

Monday, September 23, 2013

Palindrome checker using java

import java.util.*;

public class palindrome
{
   public static void main(String args[])
   {
      String original, reverse="";
      Scanner in = new Scanner(System.in);

      System.out.println("Enter a string to check if it is a palindrome");
      original = in.nextLine();
     

      int length = original.length();

      for ( int i = length - 1 ; i >= 0 ; i-- )
         reverse = reverse + original.charAt(i);

      if (original.equals(reverse))
      {
         System.out.println("Entered string is a palindrome.");
       
      }
      else
      {
         System.out.println("Entered string is not a palindrome.");
          System.out.println(reverse);
      }

   }
}

Thursday, September 12, 2013

How to sort array values in ascending / descending order using Java

Here's the idea on how to sort array; descending or ascending order: I hope this would helps.

Sample output:



import java.util.Scanner;

public class AscendingDescending
{
    public static void main(String args[])
    {
        Scanner scan = new Scanner(System.in);
        int tenNums[]=new int[10], orderedNums[]=new int[10];
        int greater;
        String choice;

        System.out.println("Enter 10 integers : ");
        for (int i=0;i<tenNums.length;i++)
        {
            System.out.print(i+1+"=> ");
            tenNums[i] = scan.nextInt();
        }
        System.out.println();

        //imperfect number ordering algorithm
        for(int indexL=0;indexL<tenNums.length;indexL++)
        {
            greater=0;
            for(int indexR=0;indexR<tenNums.length;indexR++)
            {
                if(tenNums[indexL]>tenNums[indexR])
                {
                    greater++;
                }
            }
            orderedNums[greater]=tenNums[indexL];
        }

        //ask if ascending or descending
        System.out.print("Display order :\nA - Ascending\nD - Descending\nEnter your choice : ");
        choice = scan.next();

        //output the numbers based on choice
        if(choice.equalsIgnoreCase("a"))
        {
            for(greater=0;greater<orderedNums.length;greater++)
            {
                System.out.print(orderedNums[greater]+" ");
            }
        }
        else if(choice.equalsIgnoreCase("d"))
        {
            for(greater=9;greater>-1;greater--)
            {
                System.out.print(orderedNums[greater]+" ");
            }
        }
    }
}

How to remove duplicates in an array using java without using function?

Here's a simple code for removing duplicates in String array without using function or methods. I hope this would helps.



import java.io.*;
public class Arrayremoveduplicates {

    public static void main(String[] args) throws Exception {
   
    InputStreamReader reader = new InputStreamReader(System.in);
    BufferedReader scan = new BufferedReader (reader);
   
        String [] name = new String[5];
       
        System.out.println("Enter name: ");
        for (int i=0;i<name.length;i++)
        {
         
          name[i] = scan.readLine();
    }
      System.out.println("List of 5 Names :");
   for (int a = 0; a < name.length; a++)
   {
        System.out.print(name[a] + " ");
   }
        System.out.println();
        int total=0;
        System.out.println("Names without duplicates :");
        for (int i = 0; i < name.length; i++)
        {
            int duplicate = 0;
            for (int j = i + 1; j < name.length; j++)
            {
                if (name[i].equals( name[j]))
                {
                    duplicate = duplicate + 1;
                   
                }
            }
         
            if (duplicate == 0)
            {
             total++;
                System.out.println(name[i] + " ");
            }
       
        }
            System.out.println("Number of Duplicates: " + total);
    }
}


Friday, April 27, 2012

Creating Table in HTML

Tables arrange and organize content into columns and rows. Basically, they can be made via the container tags <table></table>. Each row within the table is defined by the container tags <tr></tr>. Moreover, each cell or data within a row is defined by the container tags <td></td>.

Remember that the cells <td></td> are placed inside the rows <tr></tr> and rows are placed inside the table
<table></table>.


<html>
<head>
<title>Computer Books</title>
</head>
<body>
<caption>IT Learning</caption>
<table>
           <tr bgcolor="#ff0000">
                       <th></th>
            </tr>
            <tr>
                   <th align="center" width="200px">BOOKS</th>
                    <th align="center" width="200px">SOFTWARE</th>
                    <th align="center" width="200px">HARDWARE</th>
            </tr>
                <tr>
                   <th align="center" >Creative Design</th>
                    <th align="center" >Adobe</th>
                    <th align="center" >Asus Notebook</th>
            </tr>

         <tr>
                   <th align="center" >Office Productivity</th>
                    <th align="center" >Microsoft</th>
                    <th align="center" >inFocus Projector</th>
            </tr>

</table>
</body>
</html>

Sunday, April 15, 2012

Specifying the Background Image of a Page

You can specify the background image of the page by using the background Attribute inside the body tag
<body background="value">...</body>. However when using an image as a background of a web page you must keep in mind not to make your background image stronger than your web page or it will be hard to read the text of your Web page. You can also add a background color that matches the color of the image.

In choosing a background image, you should remember the following:

 1. Use an image that will not distract the text and main content of the page.
 2. Do not use large image file because it will take a long time to load your page.
 3. The background should not show boundaries and grids when tiled.


<html>
 <head>
</head>
      <body>
                 <body background="image.png">
                  <font face='tahoma' size='7'> BUTTERFLY </font>
      </body>
</html>

Monday, March 26, 2012

Line Breaks in HTML

Have you noticed how your Web browser treats the white spaces on your HTML file? Your Web browser ignores white spaces and pressing Enter of the Return key does not actually create a new line on the chunk of text on your Web page as seen on the code. It will create a new line for the text that you want to appear on the next line.


The <br> tag creates a line break or new line.


<html>
   
<body>

                       <br>This is the first line<br>
                       <br>This is the second line<br>
                        <br>This is the third line<br>
         
</body>
</html>


Output: