-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swapping values at last and first index of the array
- Loading branch information
1 parent
4a86fa8
commit 381a5e6
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//SWAPPING VALUES IN ARRAY STORED OF FIRST AND LAST INDEX OF ARRAY | ||
|
||
import java.util.*; | ||
public class Program | ||
{ | ||
public static void swap(int []arr,int i,int r) | ||
{ | ||
//swapping numbers by introducing third variable | ||
int s=arr[i]; | ||
arr[i]=arr[r]; | ||
arr[r]=s; | ||
} | ||
public static void main(String[] args) | ||
{ | ||
//defining array | ||
int []arr; | ||
arr=new int [5]; | ||
//array value given | ||
arr[0]=33; | ||
arr[1]=65; | ||
arr[2]=87; | ||
arr[3]=99; | ||
arr[4]=45; | ||
|
||
//swapping function applied to swap the first and last index value of array | ||
swap(arr,0,4); | ||
|
||
//after swapping the value at frist and last postion we print them | ||
for(int i=0;i<arr.length;i++) | ||
{ | ||
System.out.println(arr[i]); | ||
} | ||
} | ||
} |