In this tutorial you will learn about the Java Program to Remove Element From Array and its application with practical example.
Java Program to Remove the elements of an Array
In this tutorial, we will learn to create a Java program that will remove the elements of an Array using Java programming.
Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:
- Operators in Java Programming.
- Basic Input and Output function in Java Programming.
- Basic Java programming.
- For loop in Java programming.
- Arithmetic operations in Java Programming.
Program description to find Remove the Elements of an Array.
In this program, we will first take the input array size and the elements from the user. Then we will take a position to remove an element of the array using a for-loop. At last, we will print the array to the user using the print function.
With the help of this program, we can Remove the Elements of an Array.
import java.util.*;//importing the package for the program.
public static void main(String args)
Scanner sc = new Scanner(System.in);
//Declaring the required variable for the program.
int i,n,ps ;
//Taking the number of element for the array
System.out.println("Enter the number of elements:") ;
n = sc.nextInt();
int a = new int[n];
//Taking the elements of the array
System.out.println("Enter the elements") ;
a[i] = sc.nextInt();
//Taking the position to delete the element
System.out.println("Enter the position of the number which is to be deleted");
ps = sc.nextInt();
//Printing the array after the deletion.
System.out.println("\nOn deleting new array we get is\n");
System.out.println("a["+i+"] = "+a[i]);
In the above program, we have first initialized the required variable.
- ps = it will hold the integer value of the input elements.
- i = it will hold the integer value.
- n = it will hold the integer value of the input.
Input size and the elements of the array from the user.
Program Logic Code for the Remove of the elements of the array.
Printing the array after deletion of the element.