Computer Science, asked by Ayush679233, 5 months ago

write a program in java to Accept an array having N elements and replace all even numbers by its half and all odd numbers by its double​

Answers

Answered by void69
1

Answer:

import java.io.*;

class EvenOddSum {

public static void main(String args[])

{

int arr[] = { 1, 2, 3, 4, 5, 6 };

int even = 0, odd = 0;

// Loop to find even, odd sum

for (int i = 0; i < arr.length; i++) {

if (i % 2 == 0)

even += arr[i];

else

odd += arr[i];

}

System.out.println("Even index positions sum: " + even);

System.out.println("Odd index positions sum: " + odd);

}

}

Explanation:

TRY in IDLE and tell me working or not;

PLEASE follow me....

Similar questions