Write A Program To Calculate Factorial of A Number
Write A Program To Calculate Factorial of A Number
Solution:-
if(n==0||n==1)
return 1;
else
return (n*fact(n-1));
int n = sc.nextInt();
System.out.println(res);
2. Write a program that accepts an integer as input and prints the table of
that integer up to 12.
Solution:-
import java.util.*;
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int mul=0;
for(int i=1;i<=12;i++)
mul = n*i;
System.out.println(n+"x"+i+"="+mul);
3. Write a program that reads in a number from the user and then displays the
Hailstone sequence for that number. The problem can be expressed as
follows:
Solution:-
import java.util.*;
while(n!=1)
if(n%2==0)
n=n/2;
else
n=(3*n)+1;
count++;