Computer Science, asked by aditichauhan69, 1 year ago

hii guys plz ans my question.write a program to input a number and check whether it is an an Armstrong number or not an Armstrong number is such a number whose sum of the cube of the digits is equal to the number for example 153 is an Armstrong number because one Cube + 5 Cube + 3 Cube is equals to 153 .

Answers

Answered by Amitaritro
1

public class JavaExample {


public static void main(String[] args) {


int num = 370, number, temp, total = 0;


number = num;

while (number != 0)

{

temp = number % 10;

total = total + temp*temp*temp;

number /= 10;

}


if(total == num)

System.out.println(num + " is an Armstrong number");

else

System.out.println(num + " is not an Armstrong number");

}

}

Answered by Anonymous
10

CODE :

import java.util.*;

class armstrong

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number");

int n=sc.nextInt();

int s=0;

int cpy=n;

while(n>0)

{

int d=n%10;

s=s+(d*d*d);

n=n/10;

}

if(s==cpy)

{

System.out.println("Armstrong number");

}

else

{

System.out.println("Not armstrong number");

}

}

}

--------------------------------------------------------------

Hope it helps :-)

__________________________________________________________________

Similar questions