public class myProg
{
public static void main(String[] args)
{
double[] myList = {1, 2, 3, 4, 5, 6, 7, 8};
// Write a program to swap adjacent elements
for ( int i = 0; i < myList.length; i += 2 )
{
double h = myList[i];
myList[i] = myList[i+1];
myList[i+1] = h;
}
for ( int i = 0; i < myList.length; i++ )
System.out.print( myList[i] + " " );
}
}
|