//Program to print armstrong between a range
//Developed by Ahlam Ansari
import java.io.*;
import java.util.*;
class armstrongSeriesRange
{
public static void main(String ahlam[])
{
int s=0,r,n,m, z,p=0,j=1;
Scanner d=new Scanner(System.in);
System.out.println("Enter the Start range");
z=d.nextInt();
System.out.println("Enter the End range");
n=d.nextInt();
for (int i=z;i<=n;i++)
{
m=i;
s=0;
p=0;
while(m!=0)
{
m=m/10;
p++;
}
int a=i;
while(a!=0)
{
r=a%10;
s=s+(int)Math.pow(r,p);
a=a/10;
}
if(i==s)
System.out.print(i+ "\n");
}
}
}
/*
Output
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>javac armstrongSeriesRange.java
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>java armstrongSeriesRange
Enter the Start range
152
Enter the End range
500
153
370
371
407
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>
*/
//Developed by Ahlam Ansari
import java.io.*;
import java.util.*;
class armstrongSeriesRange
{
public static void main(String ahlam[])
{
int s=0,r,n,m, z,p=0,j=1;
Scanner d=new Scanner(System.in);
System.out.println("Enter the Start range");
z=d.nextInt();
System.out.println("Enter the End range");
n=d.nextInt();
for (int i=z;i<=n;i++)
{
m=i;
s=0;
p=0;
while(m!=0)
{
m=m/10;
p++;
}
int a=i;
while(a!=0)
{
r=a%10;
s=s+(int)Math.pow(r,p);
a=a/10;
}
if(i==s)
System.out.print(i+ "\n");
}
}
}
/*
Output
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>javac armstrongSeriesRange.java
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>java armstrongSeriesRange
Enter the Start range
152
Enter the End range
500
153
370
371
407
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>
*/
No comments:
Post a Comment