please help!! Write an error-free Java program to do the following things. 1. In
ID: 3885597 • Letter: P
Question
please help!!
Explanation / Answer
Source Code:
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class CheckPrime
{
// To find minimum sum of
// product of number
public static long findSmallestFactor(int num)
{
for (int i = 2; i*i<= num; i++)
{
if (num % i == 0)
{
return i;
}
}
return num;
}
// The following method will check for the whether the entered number is prime or not
public static void CheckPrime(int num)
{
int i,m=0,flag=0;
m=num/2;
for(i=2;i<=m;i++){
if(num%i==0){
System.out.println(" Your Number "+num+" is not prime");
flag=1;
break;
}
}
if(flag==0)
System.out.println(" Your Number "+num+" is prime");
}
public static void main (String[] args) throws java.lang.Exception
{
int num1,num2;
Scanner sc=new Scanner(System.in);
do
{
System.out.println("Enter Integer1 and Integer2");
num1=sc.nextInt(); // Read num1
num2=sc.nextInt(); // Read num2
System.out.println("Integer 1: "+num1);
System.out.println("Integer 2: "+num2);
}while(num1>5000000|| num2>5000000);
int i,m=0,flag=0;
CheckPrime(num1);
System.out.println("The Smallest non unity factor of the "+num2+" is "+findSmallestFactor(num2));
}
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.