
to find the sum of alternate digits in a given no.

Hi Friend,
Try this:
import java.math.*;
import java.util.*;
class SumOfAlternateDigits {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter Number: ");
BigInteger bi = input.nextBigInteger();
int num = 0;
String strSum = bi.toString();
for (int i = 0; i < strSum.length(); i += 2) {
char ch = strSum.charAt(i);
int n = Integer.parseInt(Character.toString(ch));
num += n;
}
System.out.println("Sum of Alternate digits is: " + num);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.