Skip to content

Instantly share code, notes, and snippets.

@ShubhamS32
Created March 13, 2019 12:31
Show Gist options
  • Select an option

  • Save ShubhamS32/a14c693b466410f30477685b4ade9164 to your computer and use it in GitHub Desktop.

Select an option

Save ShubhamS32/a14c693b466410f30477685b4ade9164 to your computer and use it in GitHub Desktop.
SumOfElem.java
public class SumOfElem {
static int sum=0;
public static void main(String[] args) {
// TODO Auto-generated method stub
int no=3850;
int val=getValue(no);
System.out.println("The Total is:"+val);
}
public static int getValue(int a)
{
if(a<1)
{
return sum;
}else
{
int rem=a%10;
sum =sum+rem;
getValue(a/10);
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment