0% found this document useful (0 votes)
5 views2 pages

Computer F.S

The document provides a Java program that checks if a three-digit number is an Armstrong number. It prompts the user to input a number, calculates the sum of the cubes of its digits, and compares it to the original number. The output indicates whether the number is an Armstrong number or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Computer F.S

The document provides a Java program that checks if a three-digit number is an Armstrong number. It prompts the user to input a number, calculates the sum of the cubes of its digits, and compares it to the original number. The output indicates whether the number is an Armstrong number or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

COMPUTER PROGRAMS

Que. Write a program in java to accept a three-digit no.


and check whether the no. is Armstrong or not.
import java.util.*;
class Armstrong
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println(“Enter a three-digit number”);
int n=sc.nextInt();
int a=n,b=0,c;
while(a>0)
{
c=n%10;
b=c*c*c;
n=n/10;
}
if(n==b)

System.out.println(“Armstrong number”);

else

System.out.println(“not an Armstrong
number”);
}
}

Output:
Enter a number: 143
not an Armstrong number.

You might also like