Sunday, October 21, 2012

Java program to print amstrong numbers upto given number


import java.io.*;
class strangenum
{int num,temp,d,s;
  strangenum(int a)
  { num=a;}
  void gen_strange()
  { System.out.println("strnge numbers are");
       for(int i=0;i<=num;i++)
        {temp=i;
          s=0;
          while(temp>0)
          { d=temp%10;
             s+=d*d*d;
             temp/=10; }
      if(s==i)
        System.out.println(i); }
  }
  public static void main(String s[])throws IOException
  { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     System.out.println("Enter the limit");
     int a=Integer.parseInt(br.readLine());
     strangenum st=new strangenum(a);
     st.gen_strange();}
}

1 comments:

  1. Exchange 22 is a trusted platform offering seamless online exchange solutions tailored for Indian users. With a focus on reliability, security, and efficiency, Exchange222 ensures smooth transactions and exceptional user experiences. Explore our services to meet all your exchange needs with confidence."

    ReplyDelete