Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class armstrong{
- protected String num;
- armstrong(String n)//constructor to take input
- {
- num=n;
- }
- int nDig()//find the number of digits
- {
- int l=num.length();
- return l;
- }
- void outpt()
- {
- double sum=0;
- int n=nDig();
- int stor[]=new int[n];
- for(int i=0;i<n;i++)
- {
- char c=num.charAt(i);
- stor[i]=(int)c-48;
- }
- for(int i=0;i<n;i++)
- {
- //System.out.println(stor[i]+" ");
- sum=sum+Math.pow(stor[i],n);
- }
- int sm=(int)sum;
- String chk=Integer.toString(sm);
- if(num.equals(chk))
- {
- System.out.println(chk+" Amstrong number");
- }
- else
- {
- System.out.println(chk+" not Arrmstrong");
- }
- }
- }
- class O1
- {
- public static void main(String args[])
- {
- Scanner in= new Scanner(System.in);
- System.out.println("enter a number");
- String s=in.nextLine();
- armstrong a=new armstrong(s);
- a.outpt();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment