write a Java program to accept a number from the user...
To find the sum of odd numbers of the entered digit.
Ex. 1783
The sum is 1+7+3=11
Answers
Answered by
1
import java.util.*;
public class p1
{
public static void main (String args)
{
Scanner sc = new Scanner (System.in);
System.out.println("enter a number”);
int a = sc.nextInt();
int d;
int s=0;
while (a>0)
{
d=a%10;
if (d%2!=0)
{
a=a/10;
continue;
}
s=s+d;
a=a/10;
}
System.out.println("sum of odd digits = "+s);
}
}
Answered by
0
Explanation:
aare mere questions pe aao n
Similar questions