Remove prime numbers from Arraylist | Strings and Arraylists

preview_player
Показать описание

NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the problem where we are required to remove all prime numbers from an arraylist. In this problem,

1. You are given an ArrayList of positive integers.
2. You have to remove prime numbers from the given ArrayList and return the updated ArrayList.

Note - The order of elements should remain same.

Рекомендации по теме
Комментарии
Автор

The isprime function stuck in my mind and thanks a lot
We want you back continuing
Se journey

Malayalam_learner
Автор

prime k program galat hai 1 ko prime maan kr hta rha h. mera submit m yhi error de rha tha fir maine if(num<2) return false; htaya apne prime k function se toh shi hua.

AmanSinghYT
Автор

Sir left side se bhi toh i-- kr skte h loop k andar n sirji

anjneykumarsingh
Автор

sir your pepcoding online judge is considering 0 and 1 also prime no. Because of which I wasted so much time to find error in my program.
Also your program for prime is written in such a way that it considers 0 and 1 as prime.

amansrivastava
Автор

Sirji left se bhi submit krdiya maine

anjneykumarsingh
Автор

public static void solution(ArrayList < Integer > al) {
for (int i = 0; i < al.size(); i++) {
int n = al.get(i);
int count = 0;
for (int div = 1; div*div <= n; div++) {
if (n % div == 0) {
count++;
}
}
if(count == 1){
al.remove(i);
i--;
}
}
}

sir yeh bhi kr sakte hai nah?

umang
Автор

When n=1 is not handled in isPrime function

imrohan
Автор

find the prime number using string array in java
String s[] ={"2", "5", "6", "7", "3", "11", "13", "17", "18", "20"};
sir please give the solution for this

nileshjadhav