public class Program { static void Main(string[] args) { int[] nums = { 1, 2,3,4,5,6,7,8,9,10 }; int x = 3; List list = new List(); for(int i = 0; i < nums.Length; i++) { if(x != nums[i]) { list.Add(nums[i]); } } foreach(int i in list) { Console.WriteLine(i); } } }
YOU SAVED ME BRO OMG I WISH I SAW THIS 10 MINUTES AGO BEFORE MY DUE DATE thank you so so soooooo much i subscribed because of this 🥹🥹🥹🥹👏👏 I'm still so sad because it's 12 am and my mind isn't working properly if i thought to search this up earlier in stead of trouble shooting I could have submitted my assignment before the deadline. The only thing I struggled with was not adding the "index" variable like you did, so i kept getting out of bounds error. And i had so much time that I wasted so now it's late, but better late than never i guess
Thank you so much for great explanation.
what if there are more than 1 element of which you want to remove in the array? (i.e. {1, 2, 3, 3, 4} with element being 3)
It'll delete both 3's
What IDE do you use?
I think it is Eclipse IDE
Yes.. it's eclipse
sir, please catch the AIOB execption in case element not found
you must have not used same name in the method signature?
Thank you
Little bit easier one!!
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a[ ]= {1,2,3,4,5,2};
System.out.println("enter element to be deleted:-");
int b= sc.nextInt();
for(int i=0;i
Here you are not deleting but just printing
he is doing the same
@@keerthishanbhag1137
Dynamic code likhiye naa..
public class Program
{
static void Main(string[] args)
{
int[] nums = { 1, 2,3,4,5,6,7,8,9,10 };
int x = 3;
List list = new List();
for(int i = 0; i < nums.Length; i++)
{
if(x != nums[i])
{
list.Add(nums[i]);
}
}
foreach(int i in list)
{
Console.WriteLine(i);
}
}
}
👍
YOU SAVED ME BRO OMG I WISH I SAW THIS 10 MINUTES AGO BEFORE MY DUE DATE
thank you so so soooooo much i subscribed because of this 🥹🥹🥹🥹👏👏
I'm still so sad because it's 12 am and my mind isn't working properly if i thought to search this up earlier in stead of trouble shooting I could have submitted my assignment before the deadline.
The only thing I struggled with was not adding the "index" variable like you did, so i kept getting out of bounds error. And i had so much time that I wasted so now it's late, but better late than never i guess
Thank you