Computer Science, asked by lakshmiadnala, 10 months ago

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 sruthirahini
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 abhisheksharma4122
0

Explanation:

aare mere questions pe aao n

Similar questions