Computer Science, asked by visheshagarwal153, 7 months ago

Write a program to input a number and print if it's Armstrong or not.

Java​

Answers

Answered by stylishtamilachee
13

Answer:

import java.util.Scanner ;

public class Armstrong

{

public static void main (String args[ ] )

{

Scanner sc = new Scanner(System.in) ;

System.out.print("Enter a 3digit number to be checked:") ;

int num= sc.nextInt( ) ;

int check = 0, remainder;

do {

remainder = n % 10 ;

check = check + (int)Math.pow(remainder,3) ;

n = n / 10 ;

} while (n != 0) ;

if (check = = num )

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

else

System.out.println(num + "is not a Armstrong Number") ;

}

}

Example output:

Enter a 3 digit number to be checked : 345

345 is not a Armstrong number

Answered by Anonymous
8

import java.util.Scanner ;

public class Armstrong

{

public static void main (String args[ ] )

{

Scanner sc = new Scanner(System.in) ;

System.out.print("Enter a 3digit number to be checked:") ;

int num= sc.nextInt( ) ;

int check = 0, remainder;

do {

remainder = n % 10 ;

check = check + (int)Math.pow(remainder,3) ;

n = n / 10 ;

} while (n != 0) ;

if (check = = num )

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

else

System.out.println(num + "is not a Armstrong Number") ;

}

}

Similar questions