So, the last task (Odd or Even). I don't see the following int variables initialized to zero anywhere, but the program somehow works just fine without errors:
public static int even;
public static int odd;
What am I missing?
TIA!
package com.codegym.task.task06.task0606;
import java.io.*;
/*
Even and odd digits
*/
public class Solution {
public static int even;
public static int odd;
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
//even = 0;
//odd = 0;
for (int i = 0; i<input.length(); i++){
//System.out.println(input.charAt(i));
int x = input.charAt(i)-'0';
//System.out.println(x);
if (x%2==0){
even++;
}
else{
odd++;
}
}
System.out.println("Even: "+even+" Odd: "+odd);
}
}