So far I've built this thing in 3 different ways, and I keep failing these requirements. The output seems to be correct though. Am I missing something?
package com.codegym.task.task06.task0606;
import java.io.*;
/*
Even and odd digits
*/
public class Solution {
public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static int even = 0;
public static int odd = 0;
public static void main(String[] args) throws IOException {
String input = reader.readLine();
String[] inputAsArray = input.split("");
for (int i = 0; i <= (inputAsArray.length - 1); i++) {
if (!inputAsArray[i].equals("-")) {
int digit = Integer.parseInt(inputAsArray[i]);
if (digit % 2 == 0) {
even++;
} else {
odd++;
}
}
}
System.out.println("Even: " + even + " Odd: " + odd);
}
}
package com.codegym.task.task06.task0606;
import java.io.*;
/*
Even and odd digits
*/
public class Solution {
public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static int even = 0;
public static int odd = 0;
public static void main(String[] args) throws IOException {
String input = reader.readLine();
String[] inputAsArray = input.split("");
for (int i = 0; i <= (inputAsArray.length - 1); i++) {
if (!inputAsArray[i].equals("-")) {
int digit = Integer.parseInt(inputAsArray[i]);
if (digit % 2 == 0) {
even = (even + 1);
} else {
odd = (odd + 1);
}
}
}
int a = even;
int b = odd;
System.out.println("Even: " + a + " Odd: " + b);
}
}