0% found this document useful (0 votes)
31 views1 page

Prime Factors in Java Code

This Java code takes a user-inputted number and finds all of its prime factors by using a nested while loop to check each potential factor for primality. It divides the input number by integers from 1 to the number, and for each factor it uses another while loop to check if that integer is only divisible by 1 and itself, labeling any such factors as prime and outputting them.

Uploaded by

dodda12345
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Prime Factors in Java Code

This Java code takes a user-inputted number and finds all of its prime factors by using a nested while loop to check each potential factor for primality. It divides the input number by integers from 1 to the number, and for each factor it uses another while loop to check if that integer is only divisible by 1 and itself, labeling any such factors as prime and outputting them.

Uploaded by

dodda12345
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Prime factors of a number in java Java code to get the prime factors of give number import [Link].

*; class Test { public static void main(String[] args) throws IOException { int num,i=1,j,k; [Link]("Enter the range:"); BufferedReader br=new BufferedReader(new InputStreamReader ([Link])); num=[Link]([Link]()); while(i<=num){ k=0; if(num%i==0){ j=1; while(j<=i){ if(i%j==0) k++; j++; } if(k==2) [Link](i+" is a prime factor"); } i++; } } }

You might also like