Computer Science, asked by sreerupasen034, 11 months ago

wap that reads a set of integers and prints the sum of the odd and even separately using scanner class and for loop.write the proper code​

Answers

Answered by syedashiq2005
0

Answer:

Hello

Explanation:

his is what I have so far. I am supposed to write this code with a For loop and if/else statement, but /i am stuck on how to do it properly. It would be nice if someone can tell me how to properly use a For loop and if/else statement together instead of giving the answer:

import java.util.*;

public class SumEvenOdd

{

public static void main(String []args)

{

Scanner keyboard= new Scanner(System.in);

int counter;

int i= 0;

int num=0;

int sumOdd= 0;

int sumEven= 0;

System.out.println("Enter integers other then Zero: ");

num=keyboard.nextInt();

System.out.println("The numbers you entered are: ");

for (i =num; i !=0; i=i)

{

if (i % 2 == 0)

sumEven = sumEven + i;

else

sumOdd = sumOdd + i;

i = keyboard.nextInt();

}

System.out.println("Even sum: " + sumEven);

System.out.println("Odd sum: " + sumOdd);

}

}

Similar questions