Computer Science, asked by harindersaini2pcf8vf, 1 year ago

Write a program to input a number and print sum of its even digits and odd digits separately. (In BlueJ)...please answer fast...


harindersaini2pcf8vf: what ?
harindersaini2pcf8vf: I did not understand what you meant.

Answers

Answered by nain31
14
import java. until. *;
public class check
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System. out. println("Enter the number ");
int n=in.nextInt();
int m=n;
int s,o=0,e=0;
while(m>0)
{
s=m%10;
m=m/10;
if(s%2==0)
e=e+s;
if(s%2!=0)
o=o+s;
}
System. out. println("The sum of odd number is"+o);
System. out. println("The sum of even number is"+e) ;
}
}
*************----------************
DRY RUN:---

n=123=m
s=12%10
s=3..which is an odd number...
so,o=0+3
o=1;

next time it's value will be,

s=2..which is an even. number
e=0+2
e=2

next time it's value will be,

s= 1..which is odd number and o=1 already,
o=3+1
o=4


*************----------************
OUTPUT

The sum of odd number is 4
The sum of even number is 2

Hope it helps (。’▽’。)♡

harindersaini2pcf8vf: Thank you so much...I'll surely mark it as brainliest when a second answer comes...thank you
harindersaini2pcf8vf: What does the variable s stand for ???
harindersaini2pcf8vf: Thank you :-)
Similar questions