Created
September 14, 2015 19:46
-
-
Save AnnaBoro/2c19034d2699cadd0344 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; | |
public class Frame6 { | |
public static void main(String[] args) { | |
int [] data1 = {1, 10, 5, 7, 6}; | |
int [] data2 = {0}; | |
int [] data3 = {}; | |
int [] data4 = {0, 0, 15, 25, 16}; | |
int [] data5 = {-3, 25, 2}; | |
System.out.println(getLast(data1)); | |
System.out.println(getLast(data2)); | |
System.out.println(getLast(data3)); | |
System.out.println(getLast(data4)); | |
System.out.println(getLast(data5)); | |
} | |
static int getLast(int[] data) { | |
if (data.length > 0) { | |
return data[data.length-1]; | |
} | |
else return -1; | |
} | |
} |
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; | |
public class Frame8 { | |
public static void main(String[] args) { | |
int[] data = {1, 55, 83, 0}; | |
int[] data2 = {}; | |
swap(data, 1, 2); | |
swap(data2, 7, 9); | |
} | |
static void swap(int [] data, int i, int k) { | |
if (i <= data.length && k <= data.length && data != null && i >= 0 && k >= 0) { | |
System.out.println("before : " + data[i] + " " + data[k]); | |
int temp = data[i]; | |
data[i] = data[k]; | |
data[k] = temp; | |
System.out.println("after : " + data[i] + " " + data[k]); | |
} | |
} | |
} |
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; | |
import java.util.Arrays; | |
public class Frame9 { | |
public static void main(String[] args) { | |
int[] data1 = {8, 9, 0}; | |
int[] data2 = {}; | |
printArray(data1); | |
printArray(data2); | |
} | |
static void printArray(int[] data) { | |
System.out.println(Arrays.toString(data)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment