CONVERSION OF COMMAND LINE STRING VALUE TO INTEGER VALUE

This section of JAVA contains source codes of many different type of Java Programs to learn the JAVA Basics. These Programs are well formatted and easy to understand.

CONVERSION OF COMMAND LINE STRING VALUE TO INTEGER VALUE

Postby aman_1982_2006 on September 4th, 2008, 5:58 am

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)
{
}
}
}
aman_1982_2006
 
Posts: 9
Joined: August 30th, 2008, 6:18 am

Recursion programs in java

Postby aman_1982_2006 on September 25th, 2008, 9:49 am

Code: Select all
//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);
      }
   }
}
      


aman_1982_2006
 
Posts: 9
Joined: August 30th, 2008, 6:18 am


Return to Java

Who is online

Users browsing this forum: No registered users and 0 guests

cron