- Code: Select all
//CONVERTING STRING VALUE TO INTEGER VALUE
class er
{
public static void main(String args[])
{
int a,b;
try
{
int c=(Integer.parseInt(System.in.read()));
System.out.println("sum is "+c);
}
catch(Exception e)
{
}
}
}
//CONVERTING STRING VALUE TO INTEGER VALUE
class er
{
public static void main(String args[])
{
int a,b;
try
{
int c=(Integer.parseInt(System.in.read()));
System.out.println("sum is "+c);
}
catch(Exception e)
{
}
}
}//prog to calculate fact of a no using recursion
class fact
{
int f(int n)
{
if(n==1)
return n;
else
int n=n*f(n-1);
return n;
}
}
class facto
{
public static void main(String ar[])
{
fact f1=new fact();
int x=f1.f(5);
System.out.println("factorial is "+x);
}
}
//*********************************program no 2***************************************
//prog to calculate fact of a no using recursion
class fib
{
int f(int n)
{
if(n==1)
return 0;
else if(n==2)
return 1;
else
return (f(n-2)+f(n-1));
}
}
class fibo
{
public static void main(String ar[])
{
fib f1=new fib();
for(int i=1;i<10;i++)
{
int an=f1.f(i);
System.out.println("series "+an);
}
}
}
Users browsing this forum: No registered users and 0 guests