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

Pubblicato il: 01 gennaio 1970
sul canale di: 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  

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


In questa pagina del sito puoi guardare il video online Insert any element in a Given Array | Both in Java and Javascript | Coding Metaverse della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Coding Metaverse 01 gennaio 1970, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 28 volte e gli è piaciuto 2 spettatori. Buona visione!