Monthly Archives: August 2016

Evs: chapter 1 notes

click here to download EVS chapter 1 notes

Advertisements

OOPM: java program for fibonacci series

//fibonacci w/o recursion
import java.io.*;

class Fibbo{
public static void main(String args[])
{
int n,x,y,temp;
n = Integer.parseInt(args[0]);
x=0;
y=1;
do{
System.out.print(x + ” “);
temp = x;
x = y;
y = temp + y;
n–;
}while(n>0);
}
}

*********************************************************************

//fibonacci with recursion
import java.io.*;

class Fibbo
{
void fib(int x, int y, int n)
{
int temp;
if(n<=0)
System.out.print(x + ” “);
else
{
System.out.print(x + ” “);
temp = x;
x = y;
y+=temp;
fib(x,y,–n);
}
}
}

class FibboRec{
public static void main(String args[])
{
int n;
n = Integer.parseInt(args[0]);
Fibbo f = new Fibbo();
System.out.print(“Fibonacci series:”);
f.fib(0,1,n);
}
}

OOPM: java program for reverse of number

//reverse of number w/o recursion
import java.io.*;

class Rev{
public static void main(String args[])
{
int n;
n = Integer.parseInt(args[0]);
while(n!=0)
{
System.out.print(n%10);
n/=10;
}
}
}

***********************************************************

//reverse of number with recursion
import java.io.*;

class revNum
{
void rev(int n)
{
if(n<10)
System.out.println(n);
else
{
System.out.print(n%10);
rev(n/10);
}
}
}

class RevRec{
public static void main(String args[])
{
int n;
n = Integer.parseInt(args[0]);
revNum r = new revNum();
System.out.print(“Reverse of number:”);
r.rev(n);
}
}