Skip to content

Instantly share code, notes, and snippets.

@OlgaKulikova
Last active August 29, 2015 14:07
Show Gist options
  • Save OlgaKulikova/52b675fa6d5a5d1f7434 to your computer and use it in GitHub Desktop.
Save OlgaKulikova/52b675fa6d5a5d1f7434 to your computer and use it in GitHub Desktop.
package com.Module2.Lesson1;
// Найти в массиве чисел элементы с наибольшим и наименьшим значениями.
public class Task5 {
public static void main(String[] args) {
int[] arr = new int[] {2, 5, 8, 0, 1, 9, 3};
int t;
for (int i = 0; i < arr.length; i++) {
for (int j = arr.length - 1; j > i; j--) {
if (arr[j] < arr[j - 1]) {
t = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = t;
}
}
}
int min = arr[0];
int max = arr[arr.length - 1];
System.out.println("Минимальное число в массиве = " + min);
System.out.println("Максимальное число в массиве = " + max);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment