/* Simple Java program to find whether a number is an armstrong number or not */
class Armstrong
{
int sumcube(int x)
{
int dig,sum = 0;
while(x >= 1)
{
dig = x % 10;
sum = sum + dig * dig * dig;
x = x / 10;
}
return(sum);
}
void display(int n)
{
if(sumcube (n)==n)
System.out.println(n + " is Armstrong Number");
else
System.out.println(n + " is not Armstrong Number");
}
void disp()
{
int x = 0,y = 0;
for(int k = x;k <= y;k++)
if(sumcube (k)==k)
System.out.println(k);
}
}
Subscribe to:
Post Comments (Atom)
Thanks dude it really helped
hey program suggested by you really works but can any body tell me whats wrong with this program,it is not showing me correct result.
import java.io.*;
class Armstrong{
public static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int num,r,sum=0;
String number;
System.out.println("Enter any number");
number=in.readLine();
num=Integer.parseInt(number);
while(num!=0)
{
r=num%10;
sum=sum+(r*r*r);
num=num/10;
}
if(sum==num)
System.out.println("given number is armstrong number");
else
System.out.println("given number is not an armstrong number");
}
}
Hi i am Ashu. The program posted is good but I have an alternative program. Use this one !!
import java.io.* ;
public class armstrong
{
static BufferedReader stdin = new BufferedReader(new InputStreamreader(System.in)) ;
public static void IsArmstrong() throws IOException
{
int n, flag, orig ;
double sum = 0.0 , d ;
System.out.print("\n Enter the number : ");
n = Integer.parseInt(stdin.readLine());
orig = n ;
while(n>0)
{
d = n % 10 ;
sum = sum + Math.pow(d, 3);
n = n / 10 ;
}
if(sum == orig)
System.out.print("\n " + orig + " is an Armstong number.");
else
System.out.print("\n " + orig + " is not an Armstrong number.);
}
}
here is the right one
public class Armstrong
{
public static void main(String[] argv)
{
int a,b,c=0,sum =0,k;
for(int i=1; i<=10000; i++)
{
a = b = i;
while(b!=0)
{
b = b/10;
c++;
}
while(a!=0)
{
k = a % 10;
sum = sum + (int)Math.pow(k,c);
a = a/10;
}
c=0;
if(sum==i)
{
System.out.println(i+" " + "is an armstrong number");
}
sum = 0;
}
}
}
hii
i too have wriiten one prog for armstrong no. pls check for further modifying it.
import java.lang.Math;
class ano
{
public static void main ( String[] a )
{
int x=Integer.parseInt( a[0] );
double s=0; int y; int z;int i;
for(i=1; i<= a[0].length(); i++)
{
z= a[0].length();
y= x % 10;
x= x/10 ;
s= s + java.lang.Math.pow(y,z) ;
}
int p= (int)s;
System.out.println(s);
System.out.println(p);
System.out.println(x);
int q=Integer.parseInt( a[0] );
if( p==q)
{
System.out.println( " Number is armstrong ");
}
else
{
System.out.println( " Number is not armstrong ");
}
}
}
hii
i too have wriiten one prog for armstrong no. pls check for further modifying it.
import java.lang.Math;
class ano
{
public static void main ( String[] a )
{
int x=Integer.parseInt( a[0] );
double s=0; int y; int z;int i;
for(i=1; i<= a[0].length(); i++)
{
z= a[0].length();
y= x % 10;
x= x/10 ;
s= s + java.lang.Math.pow(y,z) ;
}
int p= (int)s;
System.out.println(s);
System.out.println(p);
System.out.println(x);
int q=Integer.parseInt( a[0] );
if( p==q)
{
System.out.println( " Number is armstrong ");
}
else
{
System.out.println( " Number is not armstrong ");
}
}
}
i have error to run this program.this program do not has main function.
its showing me error...
its showing me error...
its showing me error...
import java.util.Scanner;
public class pro
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("pls enter the amstrong");
int d=s.nextInt();
int b=0;
int a=1;
for(int i=0;i<=1000;i++)
{
a=i*i*i;
b=b+a;
if(b==d)
{
System.out.println("asm");
System.exit(0);
}
}
System.out.println("not");
}
}
tum logon ku kaaam dhanda nai hai re?! :P
hi guys this is sasidharan doing my final year bca
programs must be simpler and easier to understand all the above programs have lengthy codings so i have written an easy coding to find armstrong numbers
PLS TRY IT !!!!!
PROGRAM:
class armstrong
{
public static void main(String args[])
{
int n=1000 , sum = 0,mod, m,i,a;
for(i=1;i<=n;i++)
{
mod = sum = 0;
a = i;
m = i;
do
{
mod = a % 10;
sum = sum + mod * mod * mod;
a = a/10;
}
while(a>0);
if(sum == m)
System.out.println(sum);
}
}
}
hey i am Mukul
import java.io.*;
class Armstrong{
public static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int num, r ,sum=0;
String number;
System.out.print("Enter any number : ");
number=in.readLine();
num=Integer.parseInt(number);
int orignum = num;
while(num!=0)
{
r=num%10;
sum=sum+(r*r*r);
num=num/10;
}
if(sum==orignum){
System.out.println("given number " + orignum+ " is armstrong number");
}else
System.out.println("given number " + orignum+ " is not an armstrong number");
}
}
import java.io.*;
class Armstrong{
public static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int num, r ,sum=0;
String number;
System.out.print("Enter any number : ");
number=in.readLine();
num=Integer.parseInt(number);
int orignum = num;
while(num!=0)
{
r=num%10;
sum=sum+(r*r*r);
num=num/10;
}
if(sum==orignum){
System.out.println("given number " + orignum+ " is armstrong number");
}else
System.out.println("given number " + orignum+ " is not an armstrong number");
}
}
import java.io.*;
class Armstrong{
public static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int num, r ,sum=0;
String number;
System.out.print("Enter any number : ");
number=in.readLine();
num=Integer.parseInt(number);
int orignum = num;
while(num!=0)
{
r=num%10;
sum=sum+(r*r*r);
num=num/10;
}
if(sum==orignum){
System.out.println("given number " + orignum+ " is armstrong number");
}else
System.out.println("given number " + orignum+ " is not an armstrong number");
}
}
please say me what's wrong with this program
import java.util.Scanner;
public class Armstrong
{
public static void main(String[] args)
{
int no,r,q,sum=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a no");
no = Integer.parseInt(sc.next());
while(no>0)
{
r=no%10;
sum=sum+r*r*r;
no=no/10;
}
if(no==sum)
{
System.out.println("It's a armstrong no");
}
else
{
System.out.println("It's not a armstrong no");
}
}
}
class armstrng
{
public static void main(String[] arg)
{
int a=153,b,c=0;
int org = a;
while(a>0)
{
b=a%10;
c=c+( b*b*b);
a=a/10;
}
System.out.println("c:"+c);
if(org== c)
System.out.println("armstrong");
else
System.out.println("not armstrong");
}
}
class armstrng
{
public static void main(String[] arg)
{
int a=153,b,c=0;
int org = a;
while(a>0)
{
b=a%10;
c=c+( b*b*b);
a=a/10;
}
System.out.println("c:"+c);
if(org== c)
System.out.println("armstrong");
else
System.out.println("not armstrong");
}
}
Autor
WicKed:boy
Here is the actual program which supports any number of digits..
Armstrong Number - Java Program
hi this is satya
this is simple prog to find Amstrong number
class Amstrong
{
static int cube(int num){
return num*num*num;
}
static int SumofCubes(int num){
return cube(((num /10)/10)% 10) + cube((num / 10)%10)+cube(num%10);
}
static boolean isAmstrong(int num){
return num == SumofCubes(num);
}
static void listAmstrong(){
for(int num = 100; num<1000; num++)
if(isAmstrong(num))
System.out.println(num+" "+"is an Armstrong");
}
public static void main(String[] args)
{
listAmstrong();
}
}
class Amstrong
{
static int cube(int num){
return num*num*num;
}
static int SumofCubes(int num){
return cube(((num /10)/10)% 10) + cube((num / 10)%10)+cube(num%10);
}
static boolean isAmstrong(int num){
return num == SumofCubes(num);
}
static void listAmstrong(){
for(int num = 100; num< 1000; num++)
if(isAmstrong(num))
System.out.println(num+" "+"is an Armstrong");
}
public static void main(String[] args)
{
listAmstrong();
}
}
Hi i am Suman , a class 9 student .the problem with bharti's prog is with the num. Its value changes in the loop.
Try this out--
//to check whether a number is an armstrong number
import java.io.*;
class ArmstrongNumber
{
private int n,r,sum=0,temp;
private String s;
public void main(String args[])throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.print("Enter a number: ");
s=br.readLine();
n=Integer.parseInt(s);
temp=n;
while(n!=0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(sum==temp)
System.out.print(temp+" is an armstrong number");
else
System.out.print(temp+" is not an armstrong number");
}
}
There are multiple way you can do this. Here is my way of finding Armstrong number in java
Hi,
I need help regarding a matter.
What is actually an armstrong number?
Is it the sum of the cubes of each digit or, the sum of the each digit raised to the number of digits
What is the accurate definition of an armstrong number?
Sum of the cubes of each digit or the sum of each digit raised to the number of digits?
Please help
c program for armstrong number
#include
#include
void main()
int a,b,c,d=0,e,f;
printf("enter the number");
scanf("%d",&a);
a=e;
while (a>0)
{
b=a%10;
c=b*b*b;
f=d+c;
a=a/10;
}
if(e==f)
{
printf("it is armstrong number");
}
else
{
printf("it is not armstrong number");
}
getch();
}