Last active
August 29, 2015 14:07
-
-
Save OlgaKulikova/52b675fa6d5a5d1f7434 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 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