java recursion
public static long factorial(int n) {
if (n == 1) return 1; //base case
return n * factorial(n-1);
}
java recursion
public static long factorial(int n) {
if (n == 1) return 1; //base case
return n * factorial(n-1);
}
java recursion
import java.util.Scanner;
public class SumDigit {
public static void main(String[] argh){
System.out.println("Enter int");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int sum = 0 ;
int i = 0;
print( i =Sum_of_digits(sum,n));
}
public static int Sum_of_digits(int sum,int n){
if(n<=0)
return sum ;
sum += n%10;
return Sum_of_digits(sum,n/10);
}
public static void print(int n){
System.out.print(n);
}
}
java recursion
public static long factorial(int n) {
if (n == 1) return 1; //base case
return n * factorial(n-1);
}
java recursion
import java.util.Scanner;
public class SumDigit {
public static void main(String[] argh){
System.out.println("Enter int");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int sum = 0 ;
int i = 0;
print( i =Sum_of_digits(sum,n));
}
public static int Sum_of_digits(int sum,int n){
if(n<=0)
return sum ;
sum += n%10;
return Sum_of_digits(sum,n/10);
}
public static void print(int n){
System.out.print(n);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us