Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, 29 July 2013

Change date format from dd-mm-yyyy to yyyy-mm-dd in java


import java.util.Collections;

import java.util.Vector;



/**

 *

 * @author RajBharath

 */

public class nCrCombination{



    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic here

       

        int count = 5;

        Vector prev = new Vector();

        Vector my_list = new Vector();

        for(int tot_item = 0;tot_item<=count;tot_item++)

        {

            prev.add(tot_item);

            my_list.add(tot_item);

        }

        Vector prev1 = new Vector();

        for(int tot_item = 0;tot_item<=count;tot_item++)

        {

                //System.out.println("Size = "+prev.size());

                for(int k = 0;k<prev.size();k++)

                {

                    String tmp = prev.get(k).toString();



                    String tmp_val[] = tmp.split(",");

                    int start = (int)Double.parseDouble(tmp_val[tmp_val.length-1]);

                    for(int item = start+1;item<=count;item++)

                    {

                        prev1.add(tmp+","+item);

                        my_list.add(tmp+","+item);

                        System.out.println(tmp+","+item);

                    }

                }   

               

                prev.clear();

                //System.out.println("Size = "+prev1.size());

                prev.addAll(0,prev1);

                //prev = prev1;

                prev1.clear();

        }

        System.out.println("Tot size = "+my_list.size());

           

    }

   

}




Get all Possible nCr Combinations in Java

In below code to give the results of 1 2 3 4 5. 11 12 13 14 15 nCr combination values.


import java.util.Collections;

import java.util.Vector;



/**

 *

 * @author RajBharath

 */

public class nCrCombination{



    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic here

       

        int count = 5;

        Vector prev = new Vector();

        Vector my_list = new Vector();

        for(int tot_item = 0;tot_item<=count;tot_item++)

        {

            prev.add(tot_item);

            my_list.add(tot_item);

        }

        Vector prev1 = new Vector();

        for(int tot_item = 0;tot_item<=count;tot_item++)

        {

                //System.out.println("Size = "+prev.size());

                for(int k = 0;k<prev.size();k++)

                {

                    String tmp = prev.get(k).toString();



                    String tmp_val[] = tmp.split(",");

                    int start = (int)Double.parseDouble(tmp_val[tmp_val.length-1]);

                    for(int item = start+1;item<=count;item++)

                    {

                        prev1.add(tmp+","+item);

                        my_list.add(tmp+","+item);

                        System.out.println(tmp+","+item);

                    }

                }   

               

                prev.clear();

                //System.out.println("Size = "+prev1.size());

                prev.addAll(0,prev1);

                //prev = prev1;

                prev1.clear();

        }

        System.out.println("Tot size = "+my_list.size());

           

    }

   

}



Calling Matlab function from Java

 Download matlabcontrol-4.1.0.jar library from https://code.google.com/p/matlabcontrol/

then try below code



import matlabcontrol.*;

import matlabcontrol.MatlabProxyFactory;

import matlabcontrol.MatlabProxyFactoryOptions;



/**

 *

 * @author RajBharath

 */

public class MatlabCommunication{



    /**

     * @param args the command line arguments

     */

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

    {

         // create proxy

        MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()

             .setUsePreviouslyControlledSession(true)

             .build();

        MatlabProxyFactory factory = new MatlabProxyFactory(options);

        MatlabProxy proxy = factory.getProxy();



        proxy.eval("disp('hello world')");



        // call user-defined function (must be on the path)

       



        // close connection

        proxy.disconnect();



    }



}


Java Code for Resource Allocation

Here we give the sample for resource allocation to processor.Its process based on resource execution time.


import java.io.*;

import java.util.Random;

/**

 *

 * @author RajBharath

 */

public class ResourceAllocation

{

     int job[]=null,process[]=null;

     int pointer=0;

    ResourceAllocation()

    {

        String str="";

        int n,n1,i;

      

        Random randomGenerator = new Random();

      

        //--------------Resource Allocation

      

        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));

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

        try

        {

            str = buffer.readLine();

        }

        catch(Exception e){}

        

        n = Integer.parseInt(str);

        job = new int[n];

        System.out.println("Each Resource Execution Time Randomly generated");

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

        for(i = 0;i<n;i++)

        {

            int randomInt = 1 + randomGenerator.nextInt(10);

            job[i] = randomInt;

            System.out.println(" Job - "+(i+1)+" : "+randomInt);

        }

      

        //--------------Processor Allocation

      

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

        try

        {

        str = buffer.readLine();

        }

        catch(Exception e)

        {       

        }

        n1 = Integer.parseInt(str); 

        //--------------Tread Allocation

        

        for (i=0;i<n1;i++)

        {

            try

            {

                ThreadClass thread1 = new ThreadClass(job[pointer],n,n1,i);

                thread1.start();

                pointer++;

            }

           catch(Exception e)

            {

            }

        }

    }

  

    class ThreadClass extends Thread

    {

        String message;

        int n,n1,job1,i;

        //int pointer;

        ThreadClass(int job,int n,int n1,int i)

        {

                this.job1=job;

                //this.pointer=pointer;

                this.n=n-1;

                this.n1=n1-1;

                this.i=i;

        }

        public void run()

        {

            while(true)

            {

               try

                {

                     sleep(job1);

                     if (pointer>=n1)

                     {

                         System.out.println("processor="+ i +"--> job="+job1);

                         if (pointer>n)

                         {

                             break;

                         }

                         else

                         {

                         try

                         {

                             pointer++;

                             job1 = job[pointer];

                             this.start();

                            

                         }

                         catch(Exception e){}   

                         }

                    }

                }

                catch(Exception e)

                {

                    System.out.print("Thread Error");

                } 

             }

        }

    }

    public static void main(String arg[]) throws Exception

    {

       new ResourceAllocation();

    }



}




Thursday, 8 December 2011

Dicom Image Viewer in ImageJ Tool | ImageJ Dicom viewer

ImageJ is the one of the image processing tool.Developed in java platform.This software views dicom image directly.Dicom images are medical images,like CT scanned images.This images mainly communicate in medical fields.

here we mention followings.

dicom image dataset - http://pubimage.hcuge.ch:8080/
ImageJ Tool download from - http://rsbweb.nih.gov/ij/download.html

Dicom dataset contain large amount of images their in a link.so please download it.Then you have download imageJ tool and run it. Finally you open your dicom image easily.
This imageJ tool provide 3D view also.This is very simple to show your imageJ tool.Add your dicom images in ImageJ stack.then go ImageJ plugin menu->go 3D->go volume viewer.Then you see in Dicom images in 3D view.


Related Posts Plugin for WordPress, Blogger...