Created
March 13, 2019 12:31
-
-
Save ShubhamS32/a14c693b466410f30477685b4ade9164 to your computer and use it in GitHub Desktop.
SumOfElem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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