- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqofSortAr.java
More file actions
Latest commit
18 lines (18 loc) · 549 Bytes
/
Copy pathSqofSortAr.java
File metadata and controls
18 lines (18 loc) · 549 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
importjava.util.Arrays;
publicclassSqofSortAr {
publicint[] sortedSquares(int[] nums){
intarray[] = newint[nums.length];
for(inti = 0; i < nums.length;i++){
array[i] = (int) Math.pow(nums[i],2);
}
Arrays.sort(array);
returnarray;
}
publicstaticvoidmain(String[] args){
int[] nums = {-7,-3,2,3,11};
SqofSortArobj = newSqofSortAr();
for(inti = 0; i < nums.length;i++){
System.out.print(obj.sortedSquares(nums)[i]+" ");
}
}
}