answersLogoWhite

0


Best Answer

import java.util.Sacnner;

class Delete

{

public static void man(String args[])

{

int n,i,l,j=0;

Scanner in=new Scanner(System.in);

System.out.println("enter the number of elements in the array");

n=in.nextInt();

int a[]=new int[n];

System.out.println("enter the number of elements in the array");

for(i=0;i<n;i++)

a[i]=in.nextInt();

int b[]=new int[n-1];

System.out.println("enter the location of the element to be deleted:");

l=in.nextInt();

for(i=0;i<l-1;i++)

{

b[j]=a[i];

j++;

}

for(i=l;i<n;i++)

{

b[i]=a[i];

j++;

}

for(j=0;j<n-1;j++)

{

System.out.println(b[j]+" ");

}

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a java program to delete an element from a given array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write an Algorithm to delete a last element from the array?

// Assuming you dynamically allocated this array using "new"... delete array[arraysize - 1]; arraysize--;


Program in c to delete an element in sorted array?

You cannot delete elements from an array. But you can move the elements: if (del_index &lt; no_of_elements-1) { memmove (&amp;array [del_index], &amp;array [del_index+1], sizeof (array [0]) * (no_of_elements - del_index - 1)); } --no_of_elements;


Will an array element be deleted when you retrieve it from the array?

You cannot delete from an array.


Delete an element from an options array?

Set it to null


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i &lt; array.length(); i++) { if(array[i] &gt; max) max = array[i] } return max; }


Write a program to delete an array element in c?

Enter how many elements you want to enter: 4 Enter the array elements: 10 20 30 40 Enter the location, where you want to delete: 3 Deleted value : 30 The new element list: 10 20 40


Write a program to delete an array element?

#include &lt;stdio.h&gt; #include &lt;conio.h&gt; #define size 10 void main() { int a[size],del,j,i; clrscr(); for(i=0;i&lt;size;i++) {j=i+1; printf(" Enter the %d element of array",j); scanf("%d",&amp;a[i]);} printf(" Enter the element to be deleted"); scanf("%d",&amp;del); del--; for(i=del;i&lt;size-1;i++) a[i]=a[i+1]; a[size-1]=0; printf(" Element has been deleted"); printf(" Array now is..... "); for(i=0;i&lt;size;i++) printf("%d ",a[i]); getch(); }


How are arrays processed?

Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.


What is the algorithm using c to delete duplicate elements from an array?

To detect the duplicate, you will have to write a nested loop that compares each element with all the previous elements.To actually delete the duplicate, once you find it, you have to move over all the elements after the duplicate. If the order of the elements doesn't matter, it is faster to just move the LAST array element, overwriting the duplicate element. Use a variable to keep track how many elements of the array are "usable". For example, if your array had 10 elements, and you delete 1, the array size will still be 10... but (after moving the elements over) only 9 of those elements have useful information.


How do you write a program which reads a list of ten numbers and print the list in reserve order in c program?

The simplest way is probably to read the numbers into an array and then prints each element of the array starting at the last one and moving backwards.


Write a program in c to find the largest no out of a matrix of order mn?

/* using ellipses (...) to indicate tabs for clarity */ double largest (double *array, int M, int N) { ... int i, j; ... double *element; ... double answer = array[0][0]; ... for (i=0; i&lt;M; i++) { ... ... for (j=0; j&lt;N; j++) { ... ... ... element = array + i*M + j; ... ... ... if (*element &gt; answer) answer = *element; ... ... } ... } ... return answer; }