Computer Science, asked by Amrita2282, 11 months ago

2 programs of digit extraction in java programming..


?????!!!!!!!​

Answers

Answered by pandurangtalekar3
1

Answer:

Input : n = 687

Output : 21

Input : n = 12

Output : 3

1. Iterative:

// Java program to compute

// sum of digits in number.

import java.io.*;

class GFG {

/* Function to get sum of digits */

static int getSum(int n)

{

int sum = 0;

while (n != 0)

{

sum = sum + n % 10;

n = n/10;

}

return sum;

}

// Driver program

public static void main(String[] args)

{

int n = 687;

System.out.println(getSum(n));

}

}

Explanation:

mark me as brainliest

Similar questions