//Program to check whether the no is armstrong or not
//Developed by Ahlam Ansari
import java.io.*;
import java.util.*;
class armstrong
{
public static void main(String ahlam[])
{
int s=0,r,n,m,p=0,j=1;
Scanner d=new Scanner(System.in);
System.out.println("Enter the number");
n=d.nextInt();
m=n;
while(m!=0)
{
m=m/10;
p++;
}
int a=n;
while(a!=0)
{
r=a%10;
s=s+(int)Math.pow(r,p);
a=a/10;
}
if(n==s)
System.out.print(n+ " IS Armstrong Number");
else
System.out.print(n+ " is NOT Armstrong Number");
}
}
/*
Output
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>javac armstrong.java
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java armstrong
Enter the number
153
153 IS Armstrong Number
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java armstrong
Enter the number
987
987 is NOT Armstrong Number
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>
*/
//Developed by Ahlam Ansari
import java.io.*;
import java.util.*;
class armstrong
{
public static void main(String ahlam[])
{
int s=0,r,n,m,p=0,j=1;
Scanner d=new Scanner(System.in);
System.out.println("Enter the number");
n=d.nextInt();
m=n;
while(m!=0)
{
m=m/10;
p++;
}
int a=n;
while(a!=0)
{
r=a%10;
s=s+(int)Math.pow(r,p);
a=a/10;
}
if(n==s)
System.out.print(n+ " IS Armstrong Number");
else
System.out.print(n+ " is NOT Armstrong Number");
}
}
/*
Output
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>javac armstrong.java
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java armstrong
Enter the number
153
153 IS Armstrong Number
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java armstrong
Enter the number
987
987 is NOT Armstrong Number
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>
*/
No comments:
Post a Comment