Thứ Hai, 25 tháng 8, 2014

java program to perform string reverse using Recursion

package logics;

public class reverseUsingRecurtion {

    public static void main(String []a)
    {
        String name="shahi kumar";
       
        System.out.print(reverse(name));
    }

public static String reverse(String data)
{
    if(data.length()==1)
        return data;
   
    String rev="";
   
    rev=rev+data.charAt(data.length()-1)+reverse(data.substring(0,data.length()-1));
    return rev;
       
   
}
}//class

output
---------------
ramuk ihahs

Java program to perform string reverse using Iteration

package logics;

public class stringReverseIteration {

    public static void main(String []a)
    {
       
        String name="shashi kumar";
        reverse(name);
    }


public static void reverse(String data)
{
    for(int i=data.length()-1;i>=0;i--)
    {
        System.out.print(data.charAt(i));
    }
   
}
}//class


output
--------------------
ramuk ihsahs

Java program to find sum of pairs of an array.

You have given an array of some elements  say{a1,a2,a3,.......,an}.and you also given a sum to check 'k' .Now you need to find pairs like (a1,a2,....,an)is equal to k
Example:

int arr[]={0,1,2,3,4,5,6}; and sum is 5;
solution is :
pairs are(1,4)   ,(2,3) , (0,5)

----------------------------------------------------------------------------------
Here is the solution for above problem in JAVA.



package logics;


public class sumArray
{
    public static void main(String []ar)
    {
        sumArray m=new sumArray();
        int data[]=new int[]{0,1,2,3,4,5,6};
        m.checkSum(data,5);
      
    }
   

public void checkSum(int a[],int num)
{

    System.out.print("pairs are \n");
    for(int i=0;i<a.length;i++)
    {
        int first=a[i];
        for(int j=i+1;j<a.length;j++)
        {
            int second=a[j];
            int sum=first+second;
            if(sum==num)
            {
                System.out.printf("(%d,%d)\n",first, second);
            }
        }
    }
   
}
}//class


output:
----------------
pairs are
(0,5)
(1,4)
(2,3)
 

Thứ Tư, 20 tháng 8, 2014

Changing "CSS" styles using "JAVASCRIPT"

It's very simple to change css styles using javascript.First you need to get object of DOM i'e you need to have a document object element,Finally change document element style using document.style."cssproprty"

example;

am just taken a sample text ,i changes the color of text into red by using css property color='red'.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Changing Style</title>
<script type="text/javascript">
function data()
{
document.getElementById('content').style.color='red';
}
</script>
</head>
<body onload="data()">
<center><i id="content">This information is accessed via javascript</i></center>

</body>
</html>
output
===========


Single Linked List Program in "C"

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct link
{
  int data;
  struct link *ptr;
}*head=NULL;

void insert()
{
  char point;
  do
  {
    struct link *newlink,*currentlink;
    newlink=(struct link*)malloc(sizeof(struct link));
    printf("\nEnter data into linked list");
    scanf("%d",&newlink->data);
    newlink->ptr=NULL;
    if(head==NULL)
    {
      head=newlink;
      currentlink=newlink;
    }
    else
    {
      currentlink->ptr=newlink;
      currentlink=newlink;
    }
    printf("\nDo you want to continue?");
    point=getche();

  }while(point!='n');

}
void display()
{
  struct link *iterator;
  iterator=head;
  printf("\n Data in your linked list is");
  while(iterator!=NULL)
  {
    printf("%d----->",iterator->data);
    iterator=iterator->ptr;
  }
  printf("NULL");
}
main()
{

  insert();
  display();
  return 0;

}

output
----------------------------------

Thứ Ba, 19 tháng 8, 2014

Applying Styles to child selectors in CSS


This Concept is very useful  if you ever tried to apply styles child elements of parent.

for example,lets have a program .I defined my text in <strong> element as  a single selector as well as a child selector of a <div> element.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Css demo</title>
<style type="text/css">
strong
{
background-image: url('images/back10.jpg');
font-size: 200%;
text-decoration: underline;
}
div > strong                                                                     / * child selector*/
{
font-size: 300%;
text-decoration: none;
color:yellow;
}

</style>
</head>
<body>

<center><strong>this is a data taken as an example</strong></center>
<br>
<br>

<div>
<strong>this text defined  in a division tag ,which is called as a parent to this element </strong>
</div>
</body>
</html>



 output:


Thứ Hai, 18 tháng 8, 2014

java code to find similar words in "AMITABH BACHCHAN" and "RAJNIKANTH"


import java.lang.*;
public class similar
{

static void find(String s1,String s2)
{
    StringBuffer buf1 = new StringBuffer(s1);
    StringBuffer buf2 = new StringBuffer(s2);
    int count=0;
    int l=0,q=0;
    int[] arr=new int[30];
    int[] arr1=new int[30];//required minimum size 26
    for(char j='A';j<='Z';j++)     
       
    {
        for(int i=0;i<buf1.length();i++)
        {
            if(buf1.charAt(i)==j) //compare the string1 indexes  with Alphabets
            {
                count++; //count similar alphabets
            }
    }
        arr[l]=count;
        count=0;
        l++;
    }   

    for(char j='A';j<='Z';j++)
    {
        for(int i=0;i<buf2.length();i++)
        {
            if(buf2.charAt(i)==j)//compare the string2 indexes  with Alphabets
            {
                count++; //count similar alphabets
            }
        }
        arr1[q]=count;
        count=0;
        q++;
    }
StringBuffer answer=new StringBuffer();
    count=0;
    int f=0;
    for(char ch='A';ch<='Z';ch++)
    {
        if(arr[f]!=0&&arr1[f]!=0)
        {
            count++;
            answer.append(ch);
        }
        f++;
    }
//print the common string
    System.out.println(answer);//Contain the string with common alphabets


    }
public static void main(String[] args)
{
String s1=new String("AMITABH BACHCHAN");
String s2=new String("RAJNIKANTH");
find(s1,s2);
}
}


output
AHINT