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
| public class PrintValue { | |
| public static void main(String[] args) { | |
| int[] xr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 3, 2, 1, 6, 5, 4, 9, 8, 7}; | |
| System.out.println("Length: " + xr.length); | |
| for (int i = 0; i < xr.length; i++) { | |
| System.out.print(xr[i] + " "); | |
| } | |
| } |
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
| import java.util.Random; | |
| import java.util.Scanner; | |
| public class Calculator { | |
| public static int[] createAnArray(int size) { | |
| int[] xr = new int[size]; | |
| return xr; | |
| } |
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
| public class PrintArrays { | |
| public static void main(String[] args) { | |
| byte[] a = {21, 23, 43, 45, 65, 67, 87, 89}; | |
| short[] b = {21, 23, 43, 45, 65, 67, 87, 89}; | |
| int[] c = {21, 23, 43, 45, 65, 67, 87, 89}; | |
| long[] d = {21, 23, 43, 45, 65, 67, 87, 89}; | |
| System.out.println(MyArrays.toString(a)); | |
| System.out.println(MyArrays.toString(b)); | |
| System.out.println(MyArrays.toString(c)); |
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
| import java.util.Arrays; | |
| public class ReversedWhileLoop { | |
| public static void main(String[] args) { | |
| int[] xr = {21, 22, 23, 24, 25, 30}; | |
| System.out.println(Arrays.toString(xr)); | |
| int start = 0; | |
| int end = xr.length - 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
| import java.util.Arrays; | |
| public class ReversedForLoop { | |
| public static void main(String[] args) { | |
| int[] xr = {21, 22, 23, 24, 25, 30}; | |
| System.out.println(Arrays.toString(xr)); | |
| for (int i = 0, j = xr.length - 1; i < j; i++, j--) { | |
| int temp = xr[i]; |
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
| import java.util.Arrays; | |
| public class ReversedForLoop { | |
| public static void reverse(int[] xr) { | |
| for (int i = 0, j = xr.length - 1; i < j; i++, j--) { | |
| int temp = xr[i]; | |
| xr[i] = xr[j]; | |
| xr[j] = temp; | |
| } |
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
| import java.util.Arrays; | |
| public class SecondMax { | |
| public static int secondMax(int[] xr) { | |
| int max = Integer.MIN_VALUE; | |
| int secondMax = Integer.MIN_VALUE; | |
| for (int i = 1; i < xr.length; i++) { |
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
| public class CompareArrays { | |
| public static boolean compareTwoArrays(int[] xr, int[] yr) { | |
| if (xr.length == yr.length) { | |
| for (int i = 0; i < xr.length; i++) { | |
| if (xr[i] != yr[i]) { | |
| return false; | |
| } | |
| } | |
| return true; |
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
| import java.util.Arrays; | |
| public class LastIndexOf { | |
| public static int search(int key, int[] xr) { | |
| int index = -1; | |
| for (int i = 0; i < xr.length; i++) { | |
| if (key == xr[i]) { | |
| index = i; |
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
| import java.util.Arrays; | |
| public class FirstIndexOf { | |
| public static int search(int key, int[] xr) { | |
| int index = -1; | |
| for (int i = 0; i < xr.length; i++) { | |
| if (key == xr[i]) { | |
| index = i; |