Finding sum of digits of a number until sum becomes single digit | Driver program to test the above function
import java . io . * ; class GFG { static int digSum ( int n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } public static void main ( String [ ] args ) { int n = 9999 ; System . out . println ( digSum ( n ) ) ; } }