0
I’m trying to make a program that organizes an array to put the odd numbers before the even numbers, this was my attempt, what I’m doing wrong.
Code:
System.out.print("Indique o número de elementos do array: ");
int a = scanner.nextInt();
int [] Numbers = new int [a];
String Numbers_S = "";
for ( int k = 0; k < a; k++ )
{
System.out.print("elemento na posição " + k + " do array: ");
Numbers [k] = scanner.nextInt();
}
for ( int i = 0; i < a; i++ )
{
if ( Numbers [i] % 2 != 0 )
{
Numbers_S += String.valueOf(Numbers [i]);
}
if ( Numbers [i] % 2 == 0 )
{
Numbers_S += String.valueOf(Numbers [i]);
}
}
for ( int n = 0; n < a; n++ )
{
Numbers [n] = Character.getNumericValue(Numbers_S.charAt(n));
}
String New_Numbers = Arrays.toString(Numbers);
System.out.println(New_Numbers);
And what problem does the code present ? It does not give the result you expect ? It gives error ? The goal is to manipulate the array directly ? Because the concatenation with the
String
?– Isac