Java program to find
SUM AND PRODUCT of a given Digit :
Class Sum_Product_ofDigit{
public
static void main(String args[]){
int
number =
Integer.parseInt(args[0]);
//taking value as command line argument.
int
temp = number, result=0;
//Sum
of digit
while(temp>0){
result
= result + temp;
temp--;
}
System.out.println("Sum
of Digit for "+number+" is : "+result);
//product
of digit
result = 1;
temp
= number;
while(temp
> 0){
result
= result * temp;
temp--;
}
System.out.println("Product
of Digit for "+number+" is : "+result);
}
}
No comments:
Post a Comment