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
10 odpowiedzi
+ 1
Use google to turn that logic into a Java code, and share your attempt, even if it's wrong
+ 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
+ 1
Python, SQL, and some web development and C/C++ basics
+ 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
0
You attempts first
0
I got logic but not getting code
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]);
}
}
}
}
0
your r python programmer
0
Can you give this answer in c++
0
Thanks Kilowac