Java Prime NUmbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java Prime NUmbers

Print Prime numbers PrepBuddy knows that Tina loves prime numbers, so PrepBuddy gives Tina an array of integers, and asks Tina to print only prime numbers from that array. Tina is too busy, so Tina is asking for your help. Input format First line contains test case variable T . T test cases follow: First line of each test case contains N representing the size of the array. Second line contains N space-separated integers. Output format For each test case, print only prime numbers in the same order as in the input array. Note: Array will contain atleast one prime number. Constraints 1 <= N <= 20 1 <= A [ i ] <= 1000 Example Input 2 5 1 2 3 4 5 7 19 25 23 37 26 50 100 Output 2 3 5 19 23 37

12th Oct 2019, 12:45 PM
Pranay Tupkar
Pranay Tupkar - avatar
10 Answers
+ 1
Use google to turn that logic into a Java code, and share your attempt, even if it's wrong
12th Oct 2019, 12:51 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
I got a confession, Iam not a Java programmer😂😂, so wait for some java programmer to help, I just said that because no one would help without a code, good luck! And one last thing, don't post code as plain text, write it in code playground then share it because it's much easier for people who help
12th Oct 2019, 12:59 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Python, SQL, and some web development and C/C++ basics
12th Oct 2019, 1:15 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Im assuming you know how to read in from a file and fill an array so I didnt include that. https://code.sololearn.com/cWvCUm68n29N/?ref=app
12th Oct 2019, 3:07 PM
Odyel
Odyel - avatar
0
You attempts first
12th Oct 2019, 12:47 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
I got logic but not getting code
12th Oct 2019, 12:50 PM
Pranay Tupkar
Pranay Tupkar - avatar
0
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) throws IOException { //write your code here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int[] a=new int[50]; for(int i=0;i<t;i++) { int size=sc.nextInt(); for(int j=1;j<size;j++) { a[j]=sc.nextInt(); for(int k=2;k<a[j];k++) if(a[j]%k==0) break; } System.out.println(a[j]); } } } }
12th Oct 2019, 12:56 PM
Pranay Tupkar
Pranay Tupkar - avatar
0
your r python programmer
12th Oct 2019, 1:08 PM
Pranay Tupkar
Pranay Tupkar - avatar
0
Can you give this answer in c++
12th Oct 2019, 1:31 PM
Pranay Tupkar
Pranay Tupkar - avatar
0
Thanks Kilowac
12th Oct 2019, 3:09 PM
Pranay Tupkar
Pranay Tupkar - avatar