Insert any element in a Given Array | Both in Java and Javascript | Coding Metaverse

Veröffentlicht am: 01 Januar 1970
auf dem Kanal: Coding Metaverse
28
2

───────────────✧───────────────

✣ Title:
Insert any element in a Given Array | Both in Java and Javascript | Coding Metaverse

───────────────✧───────────────

✣ Description:
In this video, I'll be showing you how to insert any element at a given Array. Watch the video, and I'm sure you'll find something useful in this tutorial.

Throughout the video, I'll explain what each line of code does and use of every variable in the program.

By the end of the video, you'll have program for inserting element in an array and a better understanding in sorting of Arrays. You can use this project as a starting point for your own coding projects, or you can continue to improve it and add new features.

I hope you enjoy this tutorial and find it helpful. Don't forget to like and comment your feedbacks or doubts regarding this topic, I'll definitely try to clear it out.

Contact me through my Gmail : codingmetaverseofficial@gmail.com

───────────────✧───────────────

✣ Timestamps:

0:00 Intro
0:24 Programming to Insert Element (in Java)
3:29 The Final Program (in Java)
3:39 Inserting an Element in an Array (in Javascript)
3:55 Output (in Console)
4:17 Outro

───────────────✧───────────────

Shifting and Inserting Elements (in Java):

// Replace G with Greater than Sign
// Replace L with Less than Sign
for(int i = n - 1; i *G*= position; i--)
{
arr[i + 1] = arr[i];
}
a[position] = element;

───────────────✧───────────────

Shifting and Inserting of Elements (in Javascript):

// Replace G with Greater than Sign
// Replace L with Less than Sign
for(let i = n - 1; i G = position; i--)
{
arr[i + 1] = arr[i];
}
a[position] = element;

───────────────✧───────────────

Inserting an Element in a Given Array (in Java):

// Replace G with Greater than Sign
// Replace L with Less than Sign
import java.util.Scanner;

public class Inserting {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.println("------------ Input ------------");
System.out.print("Enter the Size of the Array : ");
int n = sc.nextInt();
int arr[] = new int[n + 1];
for(int i = 0; i L n; i++)
{
System.out.print("Array["+i+"] = ");
arr[i] = sc.nextInt();
}
System.out.print("Enter the Element to be Inserted : ");
int element = sc.nextInt();
System.out.print("Enter the Position for the Element (between 0 to "+(n-1)+") : ");
int position = sc.nextInt();
for(int i = n - 1; i G = position; i--)
{
arr[i + 1] = arr[i];
}
a[position] = element;
System.out.println("------------ Output ------------");
for(int i = 0; i L n + 1; i++)
{
System.out.println("Array["+i+"] = "+arr[i]);
}
}
}

───────────────✧───────────────

Inserting an Element in a Given Array (in Javascript):

// Replace G with Greater than Sign
// Replace L with Less than Sign
let arr = [5, 10, 15, 20, 30, 35, 40] // Enter Array Elements Here
let n = arr.length
let element = 25 // Enter the Element to Insert here
let position = 4 // Enter the Position for Element here
for(let i = n - 1; i G = position; i--)
{
arr[i + 1] = arr[i];
}
arr[position] = element;
for(let i = 0; i L n + 1; i++)
{
console.log(`Array[${i}] = ${arr[i]}`);
}

───────────────✧───────────────

Music:

"Fragments" by @AERHEAD
   • Fragments  

───────────────✧───────────────


Auf dieser Seite können Sie das Online-Video Insert any element in a Given Array | Both in Java and Javascript | Coding Metaverse mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Coding Metaverse 01 Januar 1970 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 28 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!