-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmallest_num.java
More file actions
41 lines (32 loc) · 1.03 KB
/
Copy pathsmallest_num.java
File metadata and controls
41 lines (32 loc) · 1.03 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
import java.util.Scanner;
public class smallest_num {
public int[] smallerNumbersThanCurrent(int[] nums) {
int [] result = new int[nums.length];
for(int i = 0; i < nums.length;i++){
int count = 0;
for(int j = 0; j<nums.length;j++){
if(nums[j] < nums[i])
count++;
}
result[i] = count;
}
return result;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of elements: ");
int n = input.nextInt();
int[] nums = new int[n];
System.out.println("Enter the elements: ");
for (int i = 0; i < n; i++) {
nums[i] = input.nextInt();
}
smallest_num obj = new smallest_num ();
int[] result = obj.smallerNumbersThanCurrent(nums);
System.out.print("Result: ");
for (int num : result) {
System.out.print(num + " ");
}
input.close();
}
}