Largest prime factor of the number in JAVA

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Source Code:

import java.util.Scanner;

public class LargestPrimeNumber {

	public static void main(String s[]){
		System.out.println("Enter number for Prime Factor: ");
		Scanner obj =new Scanner(;
		long j =obj.nextLong();
		long i;
		long k=0;
				for(i=2; i<j;i++){
				System.out.println("Largest Prime factor  is : "+ j);

Leave a Reply

Your email address will not be published. Required fields are marked *