Hey guys, 100 points i have invested, I want the best answer with quality, no copy or spam is allowed!!
Write a program in java to input an integer and find that it is prime or not, and if its not prime then display its divisors.
Answers
Answer:
proved
Explanation:
import java.io.*;
class x
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,c=0;
System.out.println("enter a no.");
n= Integer.parseInt(br.readLine());
for(int i =1;i<=n;i++)
{
int r=n%i;
if(r==0)
c++;
}
if (c==2)
System.out.println("prime");
else
{
for(int j=1;j<=n;j++)
{
int r=n%i;
if(r==0)
System.out.println("not prime");
System.out.println(r);
}
}
}
}
thank me later...
Answer:
A prime number is a number which is divisible by only two numbers: 1 and itself. So, if any number is divisible by any other number, it is not a prime number.
Explanation:
public class Prime {
public static void main(String[] args) {
int num = 33, i = 2;
boolean flag = false;
while(i <= num/2)
{
// condition for nonprime number
if(num % i == 0)
{
flag = true;
break;
}
++i;
}
if (!flag)
System.out.println(num + is a prime number);
else
System.out.println(num + is not a prime number);
}
when u run the program the output will be..33 (not a prime number)
public class Prime {
public static void main(String[] args) {
int num = 29;
boolean flag = false;
for(int i = 2; i <= num/2; ++i)
{
// condition for nonprime number
if(num % i == 0)
{
flag = true;
break;
}
}
if (!flag)
System.out.println(num + is aprime number);
else
System.out.println(num + is not aprime number);
}
}
hope u it will help u