Created
December 16, 2015 14:55
-
-
Save Yur-ok/649c3415118829c75072 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package Lesson3.KeyPoint1; | |
| import java.util.Arrays; | |
| /** | |
| * Created by Юрий on 16.12.2015. | |
| */ | |
| public class SwapMethod { | |
| public static void main(String[] args) { | |
| int[] data = {1, 3, 4, 5}; | |
| int[] data1 = null; | |
| System.out.println(Arrays.toString(data)); | |
| swap(data1, 0, 3); | |
| swap(data, 3, 2); | |
| System.out.println(Arrays.toString(data)); | |
| System.out.println(Arrays.toString(data1)); | |
| } | |
| static void swap(int[] data, int i, int k) { | |
| int temp; | |
| if ((data != null) && (i < data.length && k < data.length)) { | |
| temp = data[i]; | |
| data[i] = data[k]; | |
| data[k] = temp; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ой! Действительно, этого моя программа не учитывает.