I made a program that allows me to enter any number with a limit that the user establishes, and so display the odd and even ones, but when I do, I have a comma on the right.
Even numbers are:
2, 4,
Odd numbers are:
3, 5,
How can I correct that and remove the extra comma at the end?
String pares = "";
String impares = "";
int li, num;
System.out.println("Ingrese la cantidad de nuemros a evaluar: ");
Scanner sc = new Scanner(System.in);
li = sc.nextInt();
for (int i = 1; i <= li; i++) {
System.out.println("Ingrese su numero #" + i);
num = sc.nextInt();
if (num % 2 == 0) {
pares += num + ", ";
} else {
impares += num + ", ";
}
}
System.out.println("Los numeros pares son:" );
System.out.print(pares);
System.out.println("\nLos numeros inpares pares son: ");
System.out.println(impares);