WHYYY?
package com.codegym.task.task07.task0706;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Streets and houses
Create an array of 15 integers.
2. Populate it with values from the keyboard.
3. Let the array index represent the house number. The array value at a particular index represents the number of people living in the corresponding house.
Houses with odd numbers are located on one side of the street. Those with even numbers are on the other side. Find out which side of the street has more people living on it.
4. Display the following message: "Odd-numbered houses have more residents." or "Even-numbered houses have more residents."
Note:
the house at index 0 is considered even.
Requirements:
1. The program must create an array of 15 integers.
2. The program should read numbers for the array from the keyboard.
3. The program should display "Odd-numbered houses have more residents." if the sum of odd array elements is greater than the sum of even ones.
4. The program should display "Even-numbered houses have more residents." if the sum of even array elements is greater than the sum of odd ones.
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
int []array = new int[15];
BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
int oddcounter=0;
int evencounter=0;
for(int i=0;i<array.length;i++)
{
int n = Integer.parseInt(in.readLine());
array[i]=n;
if (array[i]%2==0)
{
evencounter++;
}
else if (array[i]%2!=0)
{
oddcounter++;
}
}
if (oddcounter>evencounter)
{
System.out.println("Odd-numbered houses have more residents.");
}
else if (evencounter>oddcounter)
{
System.out.println("Even-numbered houses have more residents.");
}
}
}