How to Swap Array Values in A Single Dimension Array – Java #54

*Watch copying and pasting the quotation marks, you may have to retype them to avoid an error


———————Beginning of Source Code——————————-
//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Swap values in an array

package javaapplication40;

public class JavaApplication40 {

public static void main(String[] args)
//creating the array that I will switch the values of
int [] list = {30, 40, 500};

//printing list to test
for (int e = 0; e < 3; e++)
System.out.printf("Value = " + list[e] + "\n");

//Swapping the first and second value
int a = list[0];

list[0] = list[1];
list[1] = a;

//printing out to test
for (int j = 0; j < 3; j++)
System.out.printf("New list value = " + list[j] + "\n");

}//End of Main

}//End of Program

———————–End of Source Code———————————–

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s