×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
calculate the power of the given number in Java Multiplication of two matrix - Java Program
Java Program to Exchange Odd Position Element with Even Position Element - Java
5250    Arnab De    31/03/2019

Write a java program to exchange the every odd position element with the corresponding even position element. the array may have the odd numbers of elements or even numbers of elements.

Input: 15 7 18 21 9 12 87 25 8 5
output: 7 15 21 18 12 9 25 87 5 87

softetechnologies

Apply swap logic for every odd position element and even position element of an array. but no need to think about the total no of elements of the array. It may be even numbers of elements or odd numbers of elements

	class OddEvenExchange
	{
		public static void main()
		{
			int []arr={15,7,18,21,9,12,87,25,8,5};
			int i,temp;
			System.out.println("\nAfter Exchange");
			for(i=0;i<arr.length;i++)
			{
				System.out.print(arr[i] + " ");
			}
			for(i=0;i<arr.length;i+=2)
			{
				temp=arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
			System.out.println("\nBefore Exchange");
			for(i=0;i<arr.length;i++)
			{
				System.out.print(arr[i] + " ");
			}
		}
	}
softetechnologies
calculate the power of the given number in Java Multiplication of two matrix - Java Program
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Sri Sri Ramakrishna Paramahamsa
God is in all men, but all men are not in God; that is why we suffer.
Sri Sri Ramakrishna Paramahamsa
3727
51.71
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     41743
01/01/2018     35913
28/06/2017     33955
25/06/2018     33203
02/08/2017     32306
06/07/2017     26716
01/08/2017     26706
15/05/2017     26325
14/07/2017     21730
21/04/2018     20623
softetechnologies