Question

Please help help me with the following question in Java. Thanks Write a public member method...

Please help help me with the following question in Java. Thanks

Write a public member method that takes an array of integer (int) values and prints all the prime number values to the screen. You may assume the array is filled with values.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

class Test
{
   public static void findprime(int arr[])
   {
       for(int i=0;i<arr.length;i++)
       {
           for(int j=2;j<=arr[i];j++)
           {
               if(arr[i]%j==0 && arr[i]==j)
               System.out.print(arr[i]+" ");
               if(arr[i]%j==0 && arr[i]!=j)
               break;
              
           }
       }
   }
   public static void main (String[] args)
   {
       int k;
       Scanner sc=new Scanner(System.in);
       System.out.println("enter array size : ");
       int n=sc.nextInt();
       int [] arr=new int[n];
       System.out.println("enter array elements : ");
       for(int i=0;i<n;i++)
       {
           k=sc.nextInt();
           arr[i]=k;
       }
       System.out.print("prime number : ");
       findprime(arr);
   }
}

// OUTPUT

// If any doubt please comment

Add a comment
Know the answer?
Add Answer to:
Please help help me with the following question in Java. Thanks Write a public member method...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT