package com.codegym.task.task07.task0706;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Streets and houses
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader viv = new BufferedReader(new InputStreamReader(System.in));
int[] arr = new int[15];
for(int i = 0 ; i < 15 ; i++ )
{
arr[i]=Integer.parseInt(viv.readLine());
}
int ER = 0;
int OR = 0;
for(int i = 0 ; i < 15 ; i++ ){
if (i%2 == 0 )
ER = ER + arr[i];
else
OR = OR + arr[i];
}
if (ER > OR)
System.out.println("Even-numbered houses have more residents");
else
System.out.println("Odd-numbered houses have more residents");
//write your code here
}
}
I am not getting this ..what's the problem ??
Archived
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Ciobotaru Romeo Florin
25 June 2019, 16:24
You forgot the "." after "residents"
0
Evghenii
20 June 2019, 18:50
Check, I have gote this code.
0
Evghenii
20 June 2019, 18:49useful
public class Solution {
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
int[]a= new int[15];
int even=0;
int odd=0;
for (int i = 0; i <a.length ; i++) {
a[i]=sc.nextInt();
if (i%2==0){
even=even+a[i];
}else {
odd=odd+a[i];
}
}
// System.out.println(even);
// System.out.println(odd);
if (even<odd){
System.out.println("Odd-numbered houses have more residents." );
}else{
System.out.println("Even-numbered houses have more residents.");
}
}
}
+1
senthamil
17 June 2019, 08:20
you should not check i but you should check arr[i]%2==0
0