Write a program to find out the sum of odd & even digits in a given large integer

Chikul
Posted by Chikul under Others category on | Views : 23122
For e.g. Input = 1479386
Output:
Odd Sum = (1+7+3+6) =17
Even Sum = (4+9+8) = 21

import java.io.*;
import java.lang.*;

public class No_9
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a no : ");
int i=Integer.parseInt(br.readLine());
int n[]=new int[10];
int x;
int Even=0,Odd=0;

while(i!=0)
{
x=i%10;
if(x%2==0)
{
Even=Even+x;
}
else
{
Odd=Odd+x;
}
i=i/10;

}
System.out.println("Sum of ODD NO :"+Odd);
System.out.println("Sum of Even NO :"+Even);
}
}

Comments or Responses

Login to post response