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

Publicado el: 01 enero 1970
en el canal de: 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  

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


En esta página del sitio puede ver el video en línea Insert any element in a Given Array | Both in Java and Javascript | Coding Metaverse de Duración hora minuto segunda en buena calidad , que subió el usuario Coding Metaverse 01 enero 1970, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 28 veces y le gustó 2 a los espectadores. Disfruta viendo!