Todays class:

  1. fibonacci series:
  2. A Fibonacci Sequence is a series of whole numbers such that every third number is equal to the sum of the previous two numbers.
  3. The number of petals in a flower follows the Fibonacci sequence. The Fibonacci sequence can also be applied to finance by using four techniques including retracements, arcs, fans, and time zones.

Program:

class FIBONACCI{
public static void main(String args[]){
int n=10;
int f=0;
int s=1;
int t=0;
System.out.println(f+” “+s);
n=n-2;
while(n>0){
t=f+s;
System.out.println(t);
f=s;
s=t;

n–;
}
}
}

output:

sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac FIBONACCI.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java FIBONACCI
0 1
1
2
3
5
8
13
21
34

SWAP :

Swapping two variables refers to mutually exchanging the values of the variables.

n1, n2 is the swapping of two variables.

class Swap{
public static void main(String args[]){
int n1=10;
int n2=20;
System.out.println(n1+” “+n2);
n1=n1+n2;
n2=n1-n2;
n1=n1-n2;
System.out.println(n1+” “+n2);
}
}

output:

sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac Swap.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java Swap
10 20
20 10

swapping of three number:

n1, n2, res

class Swap1{
public static void main(String args[]){
int n1=10;
int n2=20;
int res=0;
res=n2;
n2=n1;
n1=res;
System.out.println(n1+” “+n2);
}
}

output:

sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac Swap1.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java Swap1
20 10

Odd or Even:

class WORD{
public static void main(String args[]){
String word=”sofiya”;
int i=0;
while(i<=word.length()-1){
if(i%2==0){
System.out.println(“even “+word.charAt(i));
}
else{
System.out.println(“odd “+word.charAt(i));
}
i++;
}

}
}

output:

sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac WORD.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java WORD
even s
odd o
even f
odd i
even y
odd a


Leave a comment

Design a site like this with WordPress.com
Get started