pass all the requirement without output
It's should like:
Apple
22
Bob
3
Cherry
1
0
Watermelon
But just red color Exception, like NullPointer.....
below it's my sort code, can some one find any problem? (I think it's in number sorting, but I can not locate it) Appreciate your help !!!
=====================================================
public static void sort(String[] array) {
// write your code here
// sorting numbers in descending order.
String temp;
for (int i = 0; i < array.length-2; i++) {
if(!isNumber(array[i]))
continue;
for (int j = i+1; j < array.length-1; j++) {
if(!isNumber(array[j]))
continue;
// if( array[i] < array[j])
if (Integer.parseInt(array[i])<Integer.parseInt(array[j])){
temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
}
// sorting Stings in ascending order
for (int k = 0; k < array.length-1; k++) {
if(isNumber(array[k])) continue;
for (int m = k + 1; m < array.length; m++) {
if(isNumber(array[m])) continue;
if(isGreaterThan(array[k] , array[m])) {
temp = array[m];
array[m] = array[k];
array[k] = temp;
}
}
}
}
not output , very confuse
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Henry Yao
6 April 2020, 19:26
Many Thanks,
0
Dimir
5 April 2020, 16:37
When an exception is thrown, it indicates the line number where it occurred
0
Dimir
5 April 2020, 16:35
Replace this string
on this
0