*Inner Class In Java*
Java inner class is a class which is defined in another class(outer class) is known as inner class or nested class in java.
*Syntax of Inner class or nested class :*
class OuterClass_Name
{
-----
-----
-----
class InnerClass_Name
{
-----
-----
-----
}
}
Java inner classes or nested classes can access all the data members and methods of its outer class including private data member and private methods.
There are a great relationship between java inner class and its outer class's instance.
Inner class is a part of nested class, non-static classes is known as inner class in java.
Types of Nested Class
There are two types of nested class, non-static nested class and static nested class. The non-static nested class is known as inner class in java.
*(1) non-static nested class(inner class)*
1. member inner class
2. anonymous inner class
3. local inner class
*(2) static nested class*
4. static nested class
https://cjavapoint.blogspot.com/?m=1
Java inner class is a class which is defined in another class(outer class) is known as inner class or nested class in java.
*Syntax of Inner class or nested class :*
class OuterClass_Name
{
-----
-----
-----
class InnerClass_Name
{
-----
-----
-----
}
}
Java inner classes or nested classes can access all the data members and methods of its outer class including private data member and private methods.
There are a great relationship between java inner class and its outer class's instance.
Inner class is a part of nested class, non-static classes is known as inner class in java.
Types of Nested Class
There are two types of nested class, non-static nested class and static nested class. The non-static nested class is known as inner class in java.
*(1) non-static nested class(inner class)*
1. member inner class
2. anonymous inner class
3. local inner class
*(2) static nested class*
4. static nested class
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
*Java Collections*
Collections in java is a framework. A collection allows a "group of objects to be treated as single unit". These objects can be stored, retrieved, and manipulated as a elements of collection.
Some collection allow duplicate elements and others do not. Some collection are ordered and others unordered.
*What is Framework ?*
Framework provides readymade architecture.Framework represents set of classes and interfaces.
*What is Collection*
Collection represents group of objects as single unit. Java collection framework introduced in J2SE 1.2 released. Collections are set of classes and interfaces.
By using collection, You can perform operations on data such as insertion, deletion, searching, sorting and manipulation easily. Collection is an alrternate of an java array
*What is Collection Framework in Java*
Collection framework in java is a unified architecture for storing and manipulating collections i.e group of objects. Java collection framework contains :
1.Interfaces
2.Interfaces implementer classes
3.Algorithm
Collection framework basically used to handle the data structure in java programming language.
Java collections framework provides many interfaces and classes, these are :
*Package :*
java.util package
*Classes :*
ArrayList
LinkedList
Vector
HashSet
LinkedHashSet
TreeSet
PriorityQueue
*Interfaces :*
Collection
List
Set
Queue
Dequeue
*Hierarchy of Collection Framework*
The java.util package contains all the classes and interfaces for the collection framework in java. When we wil make any collection program, we have to import java.util package in that program.
Collections in java is a framework. A collection allows a "group of objects to be treated as single unit". These objects can be stored, retrieved, and manipulated as a elements of collection.
Some collection allow duplicate elements and others do not. Some collection are ordered and others unordered.
*What is Framework ?*
Framework provides readymade architecture.Framework represents set of classes and interfaces.
*What is Collection*
Collection represents group of objects as single unit. Java collection framework introduced in J2SE 1.2 released. Collections are set of classes and interfaces.
By using collection, You can perform operations on data such as insertion, deletion, searching, sorting and manipulation easily. Collection is an alrternate of an java array
*What is Collection Framework in Java*
Collection framework in java is a unified architecture for storing and manipulating collections i.e group of objects. Java collection framework contains :
1.Interfaces
2.Interfaces implementer classes
3.Algorithm
Collection framework basically used to handle the data structure in java programming language.
Java collections framework provides many interfaces and classes, these are :
*Package :*
java.util package
*Classes :*
ArrayList
LinkedList
Vector
HashSet
LinkedHashSet
TreeSet
PriorityQueue
*Interfaces :*
Collection
List
Set
Queue
Dequeue
*Hierarchy of Collection Framework*
The java.util package contains all the classes and interfaces for the collection framework in java. When we wil make any collection program, we have to import java.util package in that program.
👍1
*Inner Class In Java*
Java inner class is a class which is defined in another class(outer class) is known as inner class or nested class in java.
*Syntax of Inner class or nested class :*
class OuterClass_Name
{
-----
-----
-----
class InnerClass_Name
{
-----
-----
-----
}
}
Java inner classes or nested classes can access all the data members and methods of its outer class including private data member and private methods.
There are a great relationship between java inner class and its outer class's instance.
Inner class is a part of nested class, non-static classes is known as inner class in java.
Types of Nested Class
There are two types of nested class, non-static nested class and static nested class. The non-static nested class is known as inner class in java.
*(1) non-static nested class(inner class)*
1. member inner class
2. anonymous inner class
3. local inner class
*(2) static nested class*
4. static nested class
For more information visit:-
https://cjavapoint.blogspot.com/?m=1
Java inner class is a class which is defined in another class(outer class) is known as inner class or nested class in java.
*Syntax of Inner class or nested class :*
class OuterClass_Name
{
-----
-----
-----
class InnerClass_Name
{
-----
-----
-----
}
}
Java inner classes or nested classes can access all the data members and methods of its outer class including private data member and private methods.
There are a great relationship between java inner class and its outer class's instance.
Inner class is a part of nested class, non-static classes is known as inner class in java.
Types of Nested Class
There are two types of nested class, non-static nested class and static nested class. The non-static nested class is known as inner class in java.
*(1) non-static nested class(inner class)*
1. member inner class
2. anonymous inner class
3. local inner class
*(2) static nested class*
4. static nested class
For more information visit:-
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
*Java Collections*
Collections in java is a framework. A collection allows a "group of objects to be treated as single unit". These objects can be stored, retrieved, and manipulated as a elements of collection.
Some collection allow duplicate elements and others do not. Some collection are ordered and others unordered.
*What is Framework ?*
Framework provides readymade architecture.Framework represents set of classes and interfaces.
*What is Collection*
Collection represents group of objects as single unit. Java collection framework introduced in J2SE 1.2 released. Collections are set of classes and interfaces.
By using collection, You can perform operations on data such as insertion, deletion, searching, sorting and manipulation easily. Collection is an alrternate of an java array
*What is Collection Framework in Java*
Collection framework in java is a unified architecture for storing and manipulating collections i.e group of objects. Java collection framework contains :
1.Interfaces
2.Interfaces implementer classes
3.Algorithm
Collection framework basically used to handle the data structure in java programming language.
Java collections framework provides many interfaces and classes, these are :
*Package :*
java.util package
*Classes :*
ArrayList
LinkedList
Vector
HashSet
LinkedHashSet
TreeSet
PriorityQueue
*Interfaces :*
Collection
List
Set
Queue
Dequeue
*Hierarchy of Collection Framework*
The java.util package contains all the classes and interfaces for the collection framework in java. When we wil make any collection program, we have to import java.util package in that program.
https://cjavapoint.blogspot.com/?m=1
Collections in java is a framework. A collection allows a "group of objects to be treated as single unit". These objects can be stored, retrieved, and manipulated as a elements of collection.
Some collection allow duplicate elements and others do not. Some collection are ordered and others unordered.
*What is Framework ?*
Framework provides readymade architecture.Framework represents set of classes and interfaces.
*What is Collection*
Collection represents group of objects as single unit. Java collection framework introduced in J2SE 1.2 released. Collections are set of classes and interfaces.
By using collection, You can perform operations on data such as insertion, deletion, searching, sorting and manipulation easily. Collection is an alrternate of an java array
*What is Collection Framework in Java*
Collection framework in java is a unified architecture for storing and manipulating collections i.e group of objects. Java collection framework contains :
1.Interfaces
2.Interfaces implementer classes
3.Algorithm
Collection framework basically used to handle the data structure in java programming language.
Java collections framework provides many interfaces and classes, these are :
*Package :*
java.util package
*Classes :*
ArrayList
LinkedList
Vector
HashSet
LinkedHashSet
TreeSet
PriorityQueue
*Interfaces :*
Collection
List
Set
Queue
Dequeue
*Hierarchy of Collection Framework*
The java.util package contains all the classes and interfaces for the collection framework in java. When we wil make any collection program, we have to import java.util package in that program.
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
import java.util.Scanner;
public class FibonaciiSeries
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter Number");
int x=s.nextInt();
int fib[]=new int [x];
fib[0]=0;
fib[1]=1;
for(int i=2;i<x;i++)
{
fib[i]=fib[i-1]+fib[i-2];
}
for(int se:fib)
{
System.out.print(se+" ");
}
}
}
https://cjavapoint.blogspot.com/?m=1
public class FibonaciiSeries
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter Number");
int x=s.nextInt();
int fib[]=new int [x];
fib[0]=0;
fib[1]=1;
for(int i=2;i<x;i++)
{
fib[i]=fib[i-1]+fib[i-2];
}
for(int se:fib)
{
System.out.print(se+" ");
}
}
}
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
import java.util.Arrays;
import java.util.LinkedHashSet;
public class ArrayExample
{
public static void main(String[] args) throws CloneNotSupportedException
{
//Array with duplicate elements
Integer[] numbers = new Integer[] {1,2,3,4,5,1,3,5};
//This array has duplicate elements
System.out.println( Arrays.toString(numbers) );
//Create set from array elements
LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>( Arrays.asList(numbers) );
//Get back the array without duplicates
Integer[] numbersWithoutDuplicates = linkedHashSet.toArray(new Integer[] {});
//Verify the array content
System.out.println( Arrays.toString(numbersWithoutDuplicates) );
}
}
https://cjavapoint.blogspot.com/?m=1
import java.util.LinkedHashSet;
public class ArrayExample
{
public static void main(String[] args) throws CloneNotSupportedException
{
//Array with duplicate elements
Integer[] numbers = new Integer[] {1,2,3,4,5,1,3,5};
//This array has duplicate elements
System.out.println( Arrays.toString(numbers) );
//Create set from array elements
LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>( Arrays.asList(numbers) );
//Get back the array without duplicates
Integer[] numbersWithoutDuplicates = linkedHashSet.toArray(new Integer[] {});
//Verify the array content
System.out.println( Arrays.toString(numbersWithoutDuplicates) );
}
}
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
❤1
import java.util.Scanner;
public class FibonaciiSeries
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter Number");
int x=s.nextInt();
int fib[]=new int [x];
fib[0]=0;
fib[1]=1;
for(int i=2;i<x;i++)
{
fib[i]=fib[i-1]+fib[i-2];
}
for(int se:fib)
{
System.out.print(se+" ");
}
}
}
https://cjavapoint.blogspot.com/?m=1
public class FibonaciiSeries
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter Number");
int x=s.nextInt();
int fib[]=new int [x];
fib[0]=0;
fib[1]=1;
for(int i=2;i<x;i++)
{
fib[i]=fib[i-1]+fib[i-2];
}
for(int se:fib)
{
System.out.print(se+" ");
}
}
}
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
*Static Nested Class*
1) Static Nested ClassIn java static nested class is a class which is defined in a class with static keyword.
static nested class cannot access non-static data member and methods of outer class. It can access only static data member of outer class including private.
Java Static Nested Class Example
class Simple
{
static int a = 700;
static class SimpleInner
{
void show()
{
System.out.println("value is"+a);
}
}
public static void main(String args[])
{
Simple.SimpleInner s = new Simple.SimpleInner();
s.show();
}
}
https://cjavapoint.blogspot.com/?m=1
1) Static Nested ClassIn java static nested class is a class which is defined in a class with static keyword.
static nested class cannot access non-static data member and methods of outer class. It can access only static data member of outer class including private.
Java Static Nested Class Example
class Simple
{
static int a = 700;
static class SimpleInner
{
void show()
{
System.out.println("value is"+a);
}
}
public static void main(String args[])
{
Simple.SimpleInner s = new Simple.SimpleInner();
s.show();
}
}
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
*Non-Static Nested Class(inner class)*
*1) Member Inner Class*
In java member inner class is a class which is defined in class but outside of a method is called member inner class.
*Java Member Inner Class Example*
Java member inner class defined in a class but outside of method of that class.
In this example we will create outer class(MemberOuter) and inner class(MemberInner) and declare a private data member in outer class and access this private data member in inner class because inner class can access all the data members and methods in inner class, including private data member and methods.
class MemberOuter
{
private int salary = 4000;//private data member of outer class
class MemberInner
{
void get()
{
System.out.println("salary is "+salary);//access in inner class
}
}
public static void main(String args[])
{
MemberOuter mo = new MemberOuter();
MemberOuter.MemberInner mi = mo.new MemberInner();
mi.get();
}
}
output : salary is 4000
*Note :*
(1) In case of java outer and inner class, Here the java compiler creates two .class files the first is MemberOuter.class and MemberOuter$MemberInner.class.
(2) If you want to instantiate inner class, you must have to create the instance of outer class and instance of inner class is created inside the instance of outer class.
*2) Anonymous Inner Class*
In java anonymous inner class is a class that have no name is called anonymous inner class. This class can be instantiated only once. It is usually declared inside a method or block.
Anonymous inner class can be created by two ways in java
Using class(abstract or concrete)
Using interface
*Java Anonymous Inner Class Example*
abstract class AIExample
{
abstract void show();
}
class Test
{
public static void main(String args[])
{
AIExample a = new AIExample()
{
void show()
{
System.out.println("Method of anonymous class");
}
};
a.show();
}
}
output : Method of anonymous class
The above example is performing anonymous by using abstract class.
*Java Anonymous Inner Class Example - Using Interface*
This is simple example of anonymous inner class using interface.
interface AnonymousExmple
{
void show();
}
class Test
{
public static void main(String args[])
{
AnonymousExmple ae = new AnonymousExmple()
{
public void show()
{
System.out.println("hello java ");
}
};
ae.show();
}
}
output : hello java
*3) Java Local Inner Class*
In java local inner class is a class which is created inside a method is called local inner class in java. If you want to invokes the method of local inner class, you must instantiate this class inside the method.
*Java Local Inner Class Example*
class LICExample
{
private int a = 40;
void show()
{
class LICExample1
{
void get()
{
System.out.println("value is "+a);
}
}
LICExample1 l = new LICExample1();
l.get();
}
public static void main(String args[])
{
LICExample ll = new LICExample();
ll.show();
}
}
output : value is 40
https://cjavapoint.blogspot.com/?m=1
*1) Member Inner Class*
In java member inner class is a class which is defined in class but outside of a method is called member inner class.
*Java Member Inner Class Example*
Java member inner class defined in a class but outside of method of that class.
In this example we will create outer class(MemberOuter) and inner class(MemberInner) and declare a private data member in outer class and access this private data member in inner class because inner class can access all the data members and methods in inner class, including private data member and methods.
class MemberOuter
{
private int salary = 4000;//private data member of outer class
class MemberInner
{
void get()
{
System.out.println("salary is "+salary);//access in inner class
}
}
public static void main(String args[])
{
MemberOuter mo = new MemberOuter();
MemberOuter.MemberInner mi = mo.new MemberInner();
mi.get();
}
}
output : salary is 4000
*Note :*
(1) In case of java outer and inner class, Here the java compiler creates two .class files the first is MemberOuter.class and MemberOuter$MemberInner.class.
(2) If you want to instantiate inner class, you must have to create the instance of outer class and instance of inner class is created inside the instance of outer class.
*2) Anonymous Inner Class*
In java anonymous inner class is a class that have no name is called anonymous inner class. This class can be instantiated only once. It is usually declared inside a method or block.
Anonymous inner class can be created by two ways in java
Using class(abstract or concrete)
Using interface
*Java Anonymous Inner Class Example*
abstract class AIExample
{
abstract void show();
}
class Test
{
public static void main(String args[])
{
AIExample a = new AIExample()
{
void show()
{
System.out.println("Method of anonymous class");
}
};
a.show();
}
}
output : Method of anonymous class
The above example is performing anonymous by using abstract class.
*Java Anonymous Inner Class Example - Using Interface*
This is simple example of anonymous inner class using interface.
interface AnonymousExmple
{
void show();
}
class Test
{
public static void main(String args[])
{
AnonymousExmple ae = new AnonymousExmple()
{
public void show()
{
System.out.println("hello java ");
}
};
ae.show();
}
}
output : hello java
*3) Java Local Inner Class*
In java local inner class is a class which is created inside a method is called local inner class in java. If you want to invokes the method of local inner class, you must instantiate this class inside the method.
*Java Local Inner Class Example*
class LICExample
{
private int a = 40;
void show()
{
class LICExample1
{
void get()
{
System.out.println("value is "+a);
}
}
LICExample1 l = new LICExample1();
l.get();
}
public static void main(String args[])
{
LICExample ll = new LICExample();
ll.show();
}
}
output : value is 40
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
👍4❤1
*Inner Class In Java*
Java inner class is a class which is defined in another class(outer class) is known as inner class or nested class in java.
*Syntax of Inner class or nested class :*
class OuterClass_Name
{
-----
-----
-----
class InnerClass_Name
{
-----
-----
-----
}
}
Java inner classes or nested classes can access all the data members and methods of its outer class including private data member and private methods.
There are a great relationship between java inner class and its outer class's instance.
Inner class is a part of nested class, non-static classes is known as inner class in java.
Types of Nested Class
There are two types of nested class, non-static nested class and static nested class. The non-static nested class is known as inner class in java.
*(1) non-static nested class(inner class)*
1. member inner class
2. anonymous inner class
3. local inner class
*(2) static nested class*
4. static nested class
For more information visit:-
https://cjavapoint.blogspot.com/2023/06/A%20Basic%20Java%20Program%20For%20Beginners%202023.html
Java inner class is a class which is defined in another class(outer class) is known as inner class or nested class in java.
*Syntax of Inner class or nested class :*
class OuterClass_Name
{
-----
-----
-----
class InnerClass_Name
{
-----
-----
-----
}
}
Java inner classes or nested classes can access all the data members and methods of its outer class including private data member and private methods.
There are a great relationship between java inner class and its outer class's instance.
Inner class is a part of nested class, non-static classes is known as inner class in java.
Types of Nested Class
There are two types of nested class, non-static nested class and static nested class. The non-static nested class is known as inner class in java.
*(1) non-static nested class(inner class)*
1. member inner class
2. anonymous inner class
3. local inner class
*(2) static nested class*
4. static nested class
For more information visit:-
https://cjavapoint.blogspot.com/2023/06/A%20Basic%20Java%20Program%20For%20Beginners%202023.html
👍1
Java Inheritance Update 2023 With Program And Example nheritance is one of the essential concepts in object-orientated programming
(OOP) that lets in you to create a new magnificence this is based on an current elegance.
Inheritance allows you to define a brand new elegance (known as a subclass or derived magnificence) via inheriting
The homes and behaviors (fields and strategies) of an existing class (called a superclass or base magnificence).
This allows for code reuse and the introduction of a hierarchy of instructions.
Here's a simple Java program that demonstrates inheritance: // Superclass (Base class)
class Animal {
String name;
Animal(String name) {
this.name = name;
}
void eat() {
System.out.println(name + " is eating.");
}
void sleep() {
System.out.println(name + " is sleeping.");
}
}
// Subclass (Derived class)
class Dog extends Animal {
Dog(String name) {
super(name); // Call the constructor of the superclass
}
void bark() {
System.out.println(name + " is barking.");
}
}
// Subclass (Derived class)
class Cat extends Animal {
Cat(String name) {
super(name); // Call the constructor of the superclass
}
void meow() {
System.out.println(name + " is meowing.");
}
}
public class InheritanceExample {
public static void main(String[] args) {
Dog dog = new Dog("Buddy");
Cat cat = new Cat("Whiskers");
dog.eat();
dog.sleep();
dog.bark();
cat.eat();
cat.sleep();
cat.meow();
}
} 👇👇👇👇👇👇 https://cjavapoint.blogspot.com/2023/09/Java%20Inheritance%20Update.html
(OOP) that lets in you to create a new magnificence this is based on an current elegance.
Inheritance allows you to define a brand new elegance (known as a subclass or derived magnificence) via inheriting
The homes and behaviors (fields and strategies) of an existing class (called a superclass or base magnificence).
This allows for code reuse and the introduction of a hierarchy of instructions.
Here's a simple Java program that demonstrates inheritance: // Superclass (Base class)
class Animal {
String name;
Animal(String name) {
this.name = name;
}
void eat() {
System.out.println(name + " is eating.");
}
void sleep() {
System.out.println(name + " is sleeping.");
}
}
// Subclass (Derived class)
class Dog extends Animal {
Dog(String name) {
super(name); // Call the constructor of the superclass
}
void bark() {
System.out.println(name + " is barking.");
}
}
// Subclass (Derived class)
class Cat extends Animal {
Cat(String name) {
super(name); // Call the constructor of the superclass
}
void meow() {
System.out.println(name + " is meowing.");
}
}
public class InheritanceExample {
public static void main(String[] args) {
Dog dog = new Dog("Buddy");
Cat cat = new Cat("Whiskers");
dog.eat();
dog.sleep();
dog.bark();
cat.eat();
cat.sleep();
cat.meow();
}
} 👇👇👇👇👇👇 https://cjavapoint.blogspot.com/2023/09/Java%20Inheritance%20Update.html
👍2
import java.util.Arrays;
import java.util.LinkedHashSet;
public class ArrayExample
{
public static void main(String[] args) throws CloneNotSupportedException
{
//Array with duplicate elements
Integer[] numbers = new Integer[] {1,2,3,4,5,1,3,5};
//This array has duplicate elements
System.out.println( Arrays.toString(numbers) );
//Create set from array elements
LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>( Arrays.asList(numbers) );
//Get back the array without duplicates
Integer[] numbersWithoutDuplicates = linkedHashSet.toArray(new Integer[] {});
//Verify the array content
System.out.println( Arrays.toString(numbersWithoutDuplicates) );
}
}
import java.util.LinkedHashSet;
public class ArrayExample
{
public static void main(String[] args) throws CloneNotSupportedException
{
//Array with duplicate elements
Integer[] numbers = new Integer[] {1,2,3,4,5,1,3,5};
//This array has duplicate elements
System.out.println( Arrays.toString(numbers) );
//Create set from array elements
LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>( Arrays.asList(numbers) );
//Get back the array without duplicates
Integer[] numbersWithoutDuplicates = linkedHashSet.toArray(new Integer[] {});
//Verify the array content
System.out.println( Arrays.toString(numbersWithoutDuplicates) );
}
}
❤1👍1
Java Interview Programs:
2)Fibonacci Series using recursion in java
class FibonacciExample2
{
static int n1=0,n2=1,n3=0;
static void printFibonacci(int count)
{
if(count>0)
{
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" "+n3);
printFibonacci(count-1);
}
}
public static void main(String args[])
{
int count=10;
System.out.print(n1+" "+n2);
//printing 0 and 1
printFibonacci(count-2);
//n-2 because 2 numbers are already printed
}
}
2)Fibonacci Series using recursion in java
class FibonacciExample2
{
static int n1=0,n2=1,n3=0;
static void printFibonacci(int count)
{
if(count>0)
{
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" "+n3);
printFibonacci(count-1);
}
}
public static void main(String args[])
{
int count=10;
System.out.print(n1+" "+n2);
//printing 0 and 1
printFibonacci(count-2);
//n-2 because 2 numbers are already printed
}
}
❤1👍1