- import java.util.Arrays;
- // ArrayUtils.java
- package myPackages.p1;
- public class ArrayUtils {
- public static int min(int[] arr) {
- int min = arr[0];
- for (int i = 1; i < arr.length; i++) {
- if (arr[i] < min) {
- min = arr[i];
- }
- }
- return min;
- }
- public static int max(int[] arr) {
- int max = arr[0];
- for (int i = 1; i < arr.length; i++) {
- if (arr[i] > max) {
- max = arr[i];
- }
- }
- return max;
- }
- public static void sort(int[] arr) {
- Arrays.sort(arr);
- }
- public static void reverse(int[] arr) {
- int start = 0;
- int end = arr.length - 1;
- while (start < end) {
- int temp = arr[start];
- arr[start] = arr[end];
- arr[end] = temp;
- start++;
- end--;
- }
- }
- }
- // Main.java
- public class Main {
- public static void main(String[] args) {
- int[] arr = {5, 3, 9, 1, 7};
- System.out.println("Original array: " + Arrays.toString(arr));
- System.out.println("Minimum element: " + myPackages.p1.ArrayUtils.min(arr));
- System.out.println("Maximum element: " + myPackages.p1.ArrayUtils.max(arr));
- myPackages.p1.ArrayUtils.sort(arr);
- System.out.println("Sorted array: " + Arrays.toString(arr));
- myPackages.p1.ArrayUtils.reverse(arr);
- System.out.println("Reversed array: " + Arrays.toString(arr));
- }
- }
[text] Week 5 .1
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: