0% found this document useful (0 votes)
24 views2 pages

Java 1

The document contains code to check if a number is prime or not and also check if a number is an Armstrong number. It takes user input for a number, uses loops and conditions to check the properties and prints the result.

Uploaded by

sanketmhetre018
Copyright
© © All Rights Reserved
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)
24 views2 pages

Java 1

The document contains code to check if a number is prime or not and also check if a number is an Armstrong number. It takes user input for a number, uses loops and conditions to check the properties and prints the result.

Uploaded by

sanketmhetre018
Copyright
© © All Rights Reserved
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

Input :-

import java.util.*;
class primeNumber
{
void primeMethod()
{
int i,m=0,flag=0;
int n;
System.out.println("enter number");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();

m=n/2;
if(n==0 ||n==1)
{
System.out.println(n +"is not prime number");
}
else
{
for (i=2;i<=m;i++)
{

if(n%i==0)
{
System.out.println(n +"is not prime number");
flag=1;
break;
}
}
if (flag == 0)
{
System.out.println(n + "is prime number");
}
}
}
}
class armstrongNumber
{
void armsMethod()
{
int number ,originalNumber,remainder,result=0;

System.out.println("enter number");
Scanner sc=new Scanner(System.in);
number=sc.nextInt();
originalNumber = number;

while(originalNumber != 0)
{
remainder=originalNumber % 10;
result += Math.pow(remainder,3);
originalNumber /= 10;
}
if(result == number)
System.out.println(number +"is an armstrong number");
else
System.out.println(number +"is not an armstrong number");
}
}
public class primeArmstrong
{
public static void main(String[]args)
{
primeNumber prime = new primeNumber();
prime.primeMethod();
armstrongNumber arms = new armstrongNumber();
arms.armsMethod();
}
}

Output :-

You might also like