Slip 16 A) Write a java program to calculate sum of digits of a given number using recursion.
Answer :
import java.util.*;
public class Slip16A {
int sum =0;
public static void main(String args[]) throws Exception{
int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the Number : ");
n =s.nextInt();
Slip16A obj = new Slip16A();
int a = obj.sum_digit(n);
System.out.println("Sum of Digit is : "+a);
}
int sum_digit(int n){
sum = n%10;
if(n==0){
return 0;
}else{
return sum +sum_digit(n/10);
}
}
}
Slip 16 B) Write a java program to accept n employee names from user. Sort them in ascending order and Display them.(Use array of object and Static keyword)
Answer :
No comments:
Post a Comment