package basic;

public class ArraysBasics {
	
	public static String getMinMax(int[] arr) {
		int len = arr.length;
		if (arr.length < 1 ) return "No elements in the array";
		int min = arr[0];
		int max = arr[0];
		for(int i = 0 ; i < arr.length; i++) {
			System.out.println("i is " + i);
			if (arr[i] > max) max = arr[i];
			if (arr[i] < min) min = arr[i];
		}
		return "The Min is" + min + "and the max is " + max;
	}

	public static void main(String[] args) {
		int arr[];
		arr = new int[10];
		int len = arr.length;
		// System.out.println(len);
		
		// Accessing the array elements
		// System.out.println(arr[0]);
		// System.out.println(arr[5]);
		
		int[] secondArray = {1,2,3,4,5}; // Dynamically allocates memory to the array from the number of elements
		// System.out.println(secondArray[4]);
		// System.out.println(secondArray.length);
		
		char chars[];
		chars = new char[10];
		
		// System.out.println(chars.length);
		
		char chars2[] = {'a', 'b' , 'c'};
		// System.out.println(chars2.length);
		for (int i = 0; i < chars2.length; i++) {
			// System.out.println(chars2[i]);
		}
		
		
		// Print all elements in an array
		int[] a = {6,8,2,9,1};
		for (int i = 0; i < a.length; i++) {
			System.out.println(a[i]);
		}
		
		// Sum all element in an array
		int sum = 0;
		for (int i = 0; i < a.length; i++ ) {
			sum = sum + a[i];
		}
		System.out.println("The Sum is "+ sum);
		
		// Max element in an array
		int max = a[0];
		int min = a[0];
		for(int i=0; i< a.length; i++) {
			if (a[i] > max) max = a[i];
			if (a[i] < min) min = a[i];
		}
		System.out.println("Min is " + min + "\nThe max is " + max);
		
		// Call the function to do the same
		System.out.println(getMinMax(a));
		
		// For each loops traversing
		double[] myarray = {5.0, 7.0, 1.0, 3.0, 9.0};
		System.out.println("Printing using foreach");
		for (double elem: myarray) {
			System.out.println(elem);
		}
	}

}

@@ -414,16 +414,554 @@
  max;%0A%09%7D
+%0A%09%0A%09public static int%5B%5D reverse1(int%5B%5D list) %7B%0A%09%09int reversed%5B%5D = new int%5Blist.length%5D;%0A%09%09for (int i=0, j=reversed.length - 1; i %3C list.length; i++, j--) %7B%0A%09%09%09reversed%5Bj%5D = list%5Bi%5D;%0A%09%09%7D%0A%09%09return reversed;%0A%09%7D%0A%09%0A%09public static int%5B%5D reverse2(int%5B%5D list) %7B%0A%09%09int result%5B%5D = new int%5Blist.length%5D;%0A%09%09int j = 0;%0A%09%09for (int i = list.length - 1; i %3E= 0; i--) %7B%0A%09%09%09result%5Bj%5D = list%5Bi%5D;%0A%09%09%09j++;%0A%09%09%7D%0A%09%09return result;%0A%09%7D%0A%09%0A%09public static void printArray(int%5B%5D toBePrinted) %7B%0A%09%09for (int elements: toBePrinted) %7B%0A%09%09%09System.out.println(elements);%0A%09%09%7D%0A%09%7D
 %0A%0A%09publi
@@ -2234,17 +2234,41 @@
 tMinMax(
-a
+new int%5B%5D %7B3, 7, 8 ,1, 0%7D
 ));%0A%09%09%0A%09
@@ -2453,18 +2453,118 @@
 (elem);%0A%09%09%7D%0A
+%09%09%0A%09%09printArray(reverse1(new int%5B%5D %7B1,2,3,4,5%7D));%0A%09%09printArray(reverse2(new int%5B%5D %7B1,2,3,4,5%7D));%0A%09%09%0A
 %09%7D%0A%0A%7D%0A

Update ArrayBasics.java