Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int rem=0;
int sum1=0;
int sum2=0;
while(n!=0) {
rem=n%10;
n=n/10;
System.out.println(rem);
if(rem%2==0) {
sum1=sum1+rem;
System.out.println("Sum of even numbers is"+sum1);
}
else
{
sum2=sum2+rem;
System.out.println("Sum of odd numbers is"+sum2);
}
}
}
}
OUTPUT
1234
4
Sum of even numbers is4
3
Sum of odd numbers is3
2
Sum of even numbers is6
1
Sum of odd numbers is4
//I want that sum of even and odd must be final i.e even=6 and odd=4 not first 4 then 6 for even and 1 and 3 for odd