Discussion about JAVA Programming
130 subscribers
10 photos
2 videos
152 files
12 links
Java + DSA Practices ( Daily Fever ) 😎
Daily Mission - 1 question per day
Download Telegram
public static int sum(int n){
int sum=0;
while(n>0){
int lastDigit = n%10;
sum= sum+lastDigit;
n=n/10;
}
return sum;

}
public static void main(String[] args) {
int n=78555;
int res=sum(n);
System.out.println(res);


}

Write a Java method to compute the sum of the digits in an integer.(Hint: Approach this question in the following way:a.Take a variable sum = 0b.Find the last digit of the numberc.Add it to the sumd.Repeat a & b until the number becomes 0 )
❤1
Try to solve this question 👉👉
Today's 5 Questions 🎯