program coding

program coding

how to rearrange the array a[1]. . a[n] even elements and odd elements? please give the example coding program.

View Answers

June 23, 2011 at 12:10 PM

Can u give me sample output u want to have output


June 23, 2011 at 2:44 PM

/*
 * Array starts with one not with zero so 
 * First element will be dummy 
 * 
 * so I have written displsy 
 */

class SortEvevOdd {

public int[] sort(int a[])
{
    /*
     * Odd element sorting
     */

    for(int i=1;i<a.length;i=i+2)
    {
        for(int j=i+2;j<a.length;j=j+2)
        {
            if(a[i]<a[j])
            {
                int temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }

    /*
     * Even element sorting
     */

    for(int i=2;i<a.length;i=i+2)
    {
        for(int j=i+2;j<a.length;j=j+2)
        {
            if(a[i]<a[j])
            {
                int temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    return a;
}

public void display(int a[])
{System.out.println("itt\teven\todd");
    for(int i=1;i<a.length;i++)
    {
        if(i%2==0)
            System.out.println(i+"\t"+a[i]);
        else
            System.out.println(i+"\t"+"\t"+a[i]);
    }

}

} public class Ref4 { public static void main(String args[]) { SortEvevOdd s=new SortEvevOdd(); int a[]={0,10,20,30,40,50,60};

    s.display(s.sort(a));
}

}









Related Tutorials/Questions & Answers:
program coding
program coding  how to rearrange the array a[1]. . a[n] even elements and odd elements? please give the example coding program.please provide the coding for this problem
program coding
program coding  how to rearrange the array a[1]. . a[n] even elements and odd elements? please give the example coding program
Advertisements
program coding
program coding  write a c program to rearrange the array a[1]. . .a[n] in such a way that all even elements precede all odd elements (not changing the order inside each of the two groups
program coding
program coding  Throughout a program text the operation "x to the power y" was denoted by x**y.It was decided that notation should be changed to x^y.how do we do that?The input text is a decimal number or not,and the number may
program coding
program coding  Throughout a program text the operation "x to the power y"was denoted by x**y. It was decided that notation should be changed to x^y.How do we do that? the input text is read character-by-character;the output
simple webdesign program with coding
simple webdesign program with coding  how to design a webpage using html   Please go through the following link: HTML Tutorials
please help me in coding this given program
please help me in coding this given program  consider the below... are the prime numbers in ascending order write a program to find the nth term in this series. (i m unable to code this program..please provide solution
please help me in coding this given program
please help me in coding this given program  consider the below... are the prime numbers in ascending order write a program to find the nth term in this series. (i m unable to code this program..please provide solution
coding
coding  I need the logout coding. can you please help me.   Please visit the following links: http://www.roseindia.net/quickguide/tomcat/Logout.shtml http://www.roseindia.net/jsp/loginstatus.shtml
coding
coding  write a program to create file using thread 1 and read the same file using thread2 and disply
coding
coding  write a program to create a file using thread1 and read the file using thread2 and display in the console
coding
coding  Write a java program to Create table - Employee containing empId String (20), empName String (50), DOB Date, deptId String(20). Primary key is empId. Foreign Key is deptId. Populate some records
online quiz program coding using jsp, jdbc odbc connection with ms. access.. Thank you.
online quiz program coding using jsp, jdbc odbc connection with ms. access.. Thank you.  please provide online quiz program coding using jsp, jdbc odbc connection with ms. access.. Thank you.   Create table test
Java Coding Standards
Java Coding Standards       Coding conventions are the rules that a programmer should govern while develop a program so that their source code can be read and maintain easily. Coding
coding C
coding C  Write a program for a GENERAL NUMBER CONVERTERS which include binary, decimal, octa and hexadecimal. You need to write the program using C language
Server Side Coding
Server Side Coding       Server Side Coding, on the other hand is the script that does not visually seen on the clients’ terminal but it supports the whole program
Coding for life cycle in threads
Coding for life cycle in threads  program for life cycle in threads
ModuleNotFoundError: No module named 'coding'
ModuleNotFoundError: No module named 'coding'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'coding' How to remove the ModuleNotFoundError: No module named 'coding'
ModuleNotFoundError: No module named 'coding'
ModuleNotFoundError: No module named 'coding'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'coding' How to remove the ModuleNotFoundError: No module named 'coding'
coding for project
coding for project  hai how to write jsp coding for project smart accessories ...... that s to navigate to another page when you click on a tag
coding shape
coding shape  i need to write a simple java program. the system must be in an applet and allows a user to choose whether to draw shapes such as circles, rectangles or lines on the screen. also, user can add circles by choosing
Java Coding
Java Coding  Hello, Can u please tel me how to improve my coding techniques.I am feeling difficulty with coding but I am perfect with my theory part
coding for chart
coding for chart  I want to convert a character into binary then convert it into its diagram in form of digital electrical signals.How can I do java coding for this diagram
coding of button
coding of button  What is code of fetching the value of button in a textbox using javascript
coding for login page
coding for login page  coding for login page
coding for anchor tags
coding for anchor tags  coding for anchor tags
coding for anchor tags
coding for anchor tags  coding for anchor tags
coding for anchor tags
coding for anchor tags  coding for anchor tags
coding for anchor tags
coding for anchor tags  coding for anchor tags
coding for online reservation
coding for online reservation  coding for online reservation
coding for updating profile
coding for updating profile  coding for updating profile
coding for forgot password
coding for forgot password  coding for forgot password
coding for update profile
coding for update profile  coding for update profile
coding for deleting file
coding for deleting file  coding for deleting file
need coding
need coding  sir i need code for simple bank application in jsp please send it   sir i need the coding for simple bank application in jsp.   Please visit the following link: Jsp Bank Application
coding in java
coding in java  write a code to calculate the product of odd integers from 1-15   class ProductOfOddIntegers { public static void main(String[] args) { long product=1; for(int i=1;i<=15;i
Coding with Ejb
Coding with Ejb  Hi Team, I am learning Ejb now. Can anybody help me how to implement this Stateful Session Bean Example by using this Hibernate example. Thanks in advance.   Sorry, actually I want simple code adding
CODING
coding
coding
coding
coding
Java coding for beginners
are especially for the beginners who want to incept the Java program from very beginning. Tutorial Java coding for beginners will enable you to know about the Java Coding and its various aspects during programming. It also introduces
j2me coding - Java Magazine
in sms using j2me. i have a problem in coding for sending and receiving sms .i have a coding for receiving sms but it not work because that program need sending... a coding for sending and receiving sms in j2me
coding for logout - Development process
coding for logout  hi.. coding for logout using the session in jsp
coding for emloyee managent system
coding for emloyee managent system  coding for employee management system
coding for employee management system
coding for employee management system  coding for employee management system
coding for re-type password
coding for re-type password  coding for re-type password
problem i coding
problem i coding  i have a problem in coding a combobox containing a number of *.java program on click one of them that program should compile and run and display the result in other window
program
program  any program of hotel or school management

Ads