import java.util.Scanner;
public class ArmstrongBTNum {
static int armstrong(int n)
{
int sum=0,rem,num,ck=0;
num=n;
while(num!=0)
{
rem=num%10;
sum=sum+(rem*rem*rem);
num=num/10;
}
return sum;
}
public static void main(String[] args) {
Scanner myScanner=new Scanner(System.in);
int a,b,i,ck;
System.out.print("Enter two numbers : ");
a=myScanner.nextInt();
b=myScanner.nextInt();
if(a>b){
a=a+b;
b=a-b;
a=a-b;
}
System.out.print("Armstrong number are : ");
for(i=a;i<=b;i++){
ck=armstrong(i);
if(ck==i){
System.out.print(i+"\t");
}
}
System.out.println();
}
}
//Enter two numbers : 1 1000
//Armstrong number are : 1 153 370 371 407
public class ArmstrongBTNum {
static int armstrong(int n)
{
int sum=0,rem,num,ck=0;
num=n;
while(num!=0)
{
rem=num%10;
sum=sum+(rem*rem*rem);
num=num/10;
}
return sum;
}
public static void main(String[] args) {
Scanner myScanner=new Scanner(System.in);
int a,b,i,ck;
System.out.print("Enter two numbers : ");
a=myScanner.nextInt();
b=myScanner.nextInt();
if(a>b){
a=a+b;
b=a-b;
a=a-b;
}
System.out.print("Armstrong number are : ");
for(i=a;i<=b;i++){
ck=armstrong(i);
if(ck==i){
System.out.print(i+"\t");
}
}
System.out.println();
}
}
//Enter two numbers : 1 1000
//Armstrong number are : 1 153 370 371 407
No comments:
Post a Comment