Ads Top

Strange numbers program using java

Strange numbers, program, using java ,practical,lab,computer

Find the strange numbers

Program

import java.lang.Exception
import java.io.*;
class Strange
{
public static void main(String args[])
{
int p=0,sum,x,y;
DataInputStream did =new DataInputStream(System.in);
System.out.println("Enter the lower and upper limit:");
try
{
int n=integer.parseInt(did.readLine());
int m=integer.parseInt(did.readLine());
System.ot.println("Strnage numbers are:");
for(int i=n;i<=m;i++)
{
sum=0;
x=i;
while(x!=0)
{
y=x%10;
double d=math.pow(y,3);
sum+=(int)(d);
x=x/10;
}
if(sum==i)
{
System.out.println(i);
p++;
}
}
Syestem.out.println("count="+p);
}
catch(Exception e)
{
System.out.println("Error");
}
}
}


Output

Enter the lower and upper limit:

1000
Strnage numbers are:
1
153
370
371
407

Count=5

No comments:

Touchfeeds. Powered by Blogger.