## Fibonacci series implementation in java

### Program to implement Fibonacci series in java

Hoping you know Fibonacci series. Below is program to implement Fibonacci series in java. In below program we have taken input from user as length of Fibonacci series.

Example of Fibonacci series

Program of Fibonacci series

Output:

Help others by sharing the content!

## Count occurrence of each character in string

### Program to count occurrence of each character in string

Below program to count each character occurred in string

Output:

We can print duplicates character only using below code

Output:

Help others by sharing the content!

## Java program to reverse a string in different ways

### Write a java program to reverse a string

Way 1: Java program to reverse a string in following way
``` Input: sita is clever Output: atis si revelc ```

Output:

Way 2: Java program to reverse a string in following way
``` Input: sita is clever Output: clever is sita ```

Output:

Way 3: Java program to reverse a string in following way
``` Input: sita is clever Output: revelc si atis ```

Output:

Help others by sharing the content!

## Java program to implement a Stack

### Write a java program to implement stack

As we know, Stack is a implementation class of Collection interface and child class of Vector collection.
Stack uses FIFO pattern. To insert element into Stack “push” is use and to remove elements from Stack “pop” is use.

Output

Help others by sharing the content!

## Program to insert, remove elements from array

### Problem statement

Program to insert, remove elements from array according to instruction

In this java program, we are taking 3 types of input from user like “insert” or “remove” or “exit”.

• If user entered “insert”, take again input as element of array from user.
• If user entered “remove”, take input as index of array from user.
• If user entered “exit”, print output and exit from program.

Output

In above program, we took 3 types of input from user. If the input is “insert” then we added element into array. If the user entered “remove” then element at index should be removed from array. If input is “exit” exit from console and print final array.

Help others by sharing the content!

## How to sort string array in java (3 different ways)

Sorting an Array of string in java
Way 1: Sort String array using CompareTo() method

Way 2: Sort String array using Arrays.sort() method

``` import java.util.*; public class Main { public static void main(String []args){ Scanner sc=new Scanner(System.in); System.out.println("Enter no of i/p elements"); int no_of_ele=sc.nextInt(); String str[]=new String[no_of_ele]; for(int i=0;i&lt;no_of_ele;i++) { str[i]=sc.next(); } Arrays.sort(str); System.out.println(Arrays.toString(str)); } } 12345678910111213141516 import java.util.*;public class Main{public static void main(String []args){Scanner sc=new Scanner(System.in);System.out.println("Enter no of i/p elements");int no_of_ele=sc.nextInt();String str[]=new String[no_of_ele];for(int i=0;i&lt;no_of_ele;i++){str[i]=sc.next();}Arrays.sort(str);System.out.println(Arrays.toString(str));}} ```

Way 3: Sort String array using Collections.sort() method

``` import java.util.*; public class Main { public static void main(String []args){ Scanner sc=new Scanner(System.in); System.out.println("Enter no of i/p elements"); int no_of_ele=sc.nextInt(); ArrayList arr=new ArrayList(); while(no_of_ele&gt;0) { arr.add(sc.next()); no_of_ele--; } System.out.println(arr); Collections.sort(arr); System.out.println(arr); } } 12345678910111213141516171819 import java.util.*;public class Main{public static void main(String []args){Scanner sc=new Scanner(System.in);System.out.println("Enter no of i/p elements");int no_of_ele=sc.nextInt();ArrayList arr=new ArrayList();while(no_of_ele&gt;0){arr.add(sc.next());no_of_ele--;}System.out.println(arr);Collections.sort(arr);System.out.println(arr); }} ```

Help others by sharing the content!