-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortAndFindSmallNumber.java
More file actions
52 lines (43 loc) · 1.21 KB
/
sortAndFindSmallNumber.java
File metadata and controls
52 lines (43 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package algorithmExamples;
/*
* @author Muhammed Fatih ÖZDİL
* @since Wed Mar 03 2021
*
*/
public class sortAndFindSmallNumber {
public static int[] sort(int[] arr){
for (int i = 0; i < arr.length; i++) {
for (int j = i+1; j < arr.length; j++) {
if(arr[i]>arr[j]){
int temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
return arr;
}
public static int minelement(int[] arr) {
for (int i = 0; i < arr.length; i++) {
boolean check = false ;
for (int j = i+1; j < arr.length; j++) {
if(arr[i]>arr[j]){
check = true;
break;
}
}
if(!check){
return arr[i];
}
}
return -1;
}
public static void main(String[] args) {
int[] arr = {6,4,5,3,7,19,2};
int [] newArr = sort(arr);
for (int i = 0; i < newArr.length; i++) {
System.out.println(newArr[i]);
}
System.out.println("smaller number is :" + minelement(arr));
}
}