Please write the following 2 programs using "JAVA" language only:
1) Write a program to check whether the number entered is a prime number or not.
2) Write a program to check whether the number entered is an armstrong number.
Best answer will be marked brainliest.
Please no spam.
Answers
Answered by
1
1)
import java.util.*;
class Sample
{
public static void main(String args[ ])
{
Scanner obj= new Scanner(System.in);
int n,i,c=0;
System.out.println("Enter a number ");
n=obj.nextInt( );
for(i=1;i<=n;i=i+1)
{
if(n%i==0)
c=c+1;
}
if(c==2)
System.out.println("Prime number ");
else
System.out.println("Not a prime number ");
}
}
import java.util.*;
class Sample
{
public static void main(String args[ ])
{
Scanner obj= new Scanner(System.in);
int n,i,c=0;
System.out.println("Enter a number ");
n=obj.nextInt( );
for(i=1;i<=n;i=i+1)
{
if(n%i==0)
c=c+1;
}
if(c==2)
System.out.println("Prime number ");
else
System.out.println("Not a prime number ");
}
}
hiramani7080:
My pleasure
Similar questions