Respuesta :
In python:
n = input("What is your number: ")
total = 0
i = 0
while i < len(n):
if int(n[i]) % 2 != 0:
total += int(n[i])
i += 1
print(total)
I hope this helps!
The code is in Java.
It calculates the sum of the odd digit of the number using a while loop and if-else structure.
We extract the last digit of the number, check if it is odd, add it to the sum if it is, then move to the next digit.
Comments are used to explain each line of code.
The output is added as an image.
//Main.java
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
//Scanner object to be able to get input from the user
Scanner input = new Scanner(System.in);
//declaring the variables
int number, digit, sum = 0;
//getting the number
number = input.nextInt();
//while loop that iterates while number is greater than 0
while(number > 0){
//get the last digit of the number
digit = number % 10;
//check if it is odd. If it is, add the digit to the sum
if(digit % 2 == 1)
sum += digit;
//divide the number by 10 to move to the next digit
number /= 10;
}
//print the sum
System.out.println(sum);
}
}
You may check a similar question at:
https://brainly.com/question/17554487
