>

Friday, February 22, 2013

Compare Two Integer Arrays

This program will compare two integer arrays and return a result number of matching numbers in those arrays :
public void arrayMatcher(int a[], int b[])
{
   
    int count=0;
    for(int i=0;i<a.length;i++)
    {
        for(int j=0;j<b.length;j++)
        {
            if((a[i])==(b[j]))
            {
                count++;
   
            }
        }
       
    }
    System.out.println(count+" numbers matches in two arrays");
   
   
} 
CONTENT WARNING:This is my own program.. It is for Educational purposes only. Please do not republish or reproduce with another name in online.

Sort Letters in a String Object

public void doSorting(String str)
    {
     char array[]=str.toCharArray();
     char temp;
     System.out.print("Given name :");
     for(int i=0;i<array.length;i++)
     {
         System.out.print(array[i]);
     }
     System.out.println();
     for(int i=0;i<array.length;i++)
     {
         for(int j=0;j<i;j++)
         {
             if(array[i]<array[j])
             {
                temp=array[j];
                array[j]=array[i];
                array[i]=temp;
             }
         }
   
     }

CONTENT WARNING:This is my own program.. It is for Educational purposes only. Please do not republish or reproduce with another name in online.
   

Reverse String in JAVA


This is the method which will reverse the given STRING :


public void myOwnstringReversing(String str)
{
    for(int i=str.length()-1;i>=0;i--)
    {
        System.out.print(str.charAt(i));
    }
}




CONTENT WARNING:
This is my own program.. It is for Educational purposes only. Anyone do not republish in your website will be punished offensively.

Wednesday, December 19, 2012

Thread Program four in Java


public class Thread_Demo extends Thread{

public void run(){
System.out.println("Some text");
}
public static void main(String[] args) throws InterruptedException{


Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();

t.start();

System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
//t.destroy();
t.resume();
System.out.println("ISALIVE :"+t.isAlive());
}

}

Thread Program three in Java


What is out put?

public class Thread_Demo extends Thread{

public void run(){
System.out.println("Some text");
}

public static void main(String[] args) throws InterruptedException {

Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
t.run();
System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
t.destroy();
System.out.println("ISALIVE :"+t.isAlive());
}

}

Thread Program Two in Java

What is output?


public class Thread_Demo extends Thread{

public void run(){
System.out.println("Some text");
}

public static void main(String[] args) throws InterruptedException {


Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();

t.start();

System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
t.destroy();
System.out.println("ISALIVE :"+t.isAlive());
}

}

Thread Program in Java

What is out put?


public class Thread_Demo extends Thread{

public void run(){
System.out.println("Some text");
}

public static void main(String[] args) throws InterruptedException {


Thread_Demo td=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
/*Thread t=new Thread(td);*/
td.start();
td.setPriority(10);
System.out.println(td.getName()+td.getPriority());
td1.run();
System.out.println(td1.getName()+td1.getPriority());
}
}