
a program to find the sum of the alternative diagit of it ex- no=123456 sum=1+3+5=9

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);
}
}
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.