Computer Science, asked by ooiuu, 1 year ago

Using scanner class, write a program to display the sum of even numbers and odd numbers separately from a set of numbers entered by user. The program terminates when the user enters any numeric character.

Answers

Answered by Anonymous
8

// A sample program to display the sum of even and odd numbers

import java.util.Scanner;

public class Sum

{

public static void main{String[]args)

{

System.out.println("Enter integers to continue & an alphabet to terminate");

int n,s1=0,s2=0;

while{in.hasNextInt());

    {

if(n%2==0)

s1=s1+n;

else

s2=s2+n};

    }

System.out.println("Tprogram terminates:");

System.out.println("The sum of even numbers =" +s1);

System.out.println("The sum of odd numbers =" +s2);

}

}


annesha43: aegjhhhu
Answered by harsh6575
0

Explanation:

use while(in.hasDouble) so loop terminates on use of non numeric numbet

Attachments:
Similar questions