I am just trying to sort the string in descending order. input provided by the user is 10,a,1,#,15,.,6 output must be 10,a,15,#,6,.,1 I have tried.
String input = JOptionPane.showInputDialog("Enter a string:");
String[] num = input.split(",");
ArrayList<String> arr = new ArrayList<>();
System.out.println(num);
for ( int i = 0; i < num.length - 1; i ++ )
{
for (int j = i + 1; j < num.length; j ++ )
{
if(Integer.parseInt(num[i])
&& Integer.parseInt(num[j])
&& num[i] < num[j]) {
String temp = num[ i ]; //swapping
num[ i ] = num[ j ];
num[ j ] = temp;
}
}
}
}
In if statement i get error. error:- The operator && is undefined for the argument type(s) int, int - The operator < is undefined for the argument type(s) java.lang.String, java.lang.String
&&is undefined for the argument typeint.||is undefined for the argument typeintas well. Your code is asking for something like:if(5 && 6)which make no sense in Java.Integer.parseInt(num[i]) && Integer.parseInt(num[j])seems meaning less