0% found this document useful (0 votes)
63 views3 pages

Armstrong Number

The document discusses Armstrong numbers, Fibonacci series, and perfect numbers. It provides definitions and examples of each concept. It also includes Java code to: 1. Check if a user-input number is an Armstrong number or not. 2. Print all Armstrong numbers between 100 and 999. 3. Print the Fibonacci series up to a number input by the user. 4. Check if a user-input number is a perfect number.

Uploaded by

Anirbaan Saha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views3 pages

Armstrong Number

The document discusses Armstrong numbers, Fibonacci series, and perfect numbers. It provides definitions and examples of each concept. It also includes Java code to: 1. Check if a user-input number is an Armstrong number or not. 2. Print all Armstrong numbers between 100 and 999. 3. Print the Fibonacci series up to a number input by the user. 4. Check if a user-input number is a perfect number.

Uploaded by

Anirbaan Saha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

ARMSTRONG NUMBER: Armstrong or Narcissistic number is the one , whose individual digits’ cube-sum is
equal to the number itself
e.g., 407 is an Armstrong number because
407 = 43+03+73
153=13+53+33

 Write a program that will accept a number and check whether


it is a Armstrong number or not.

import java.io.*;
class Armstrong1
{
public static void main (String args[])
{
System.out.println("Enter a number that will be checked. ");
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
int num = Integer.parseInt(br.readLine());
int number1=num;
int res=0,temp=0;
while(num!=0)
{
temp = num%10;
res= res + (int)Math.pow(temp,3);
num=num/10;
}
if(res==number1)
{
System.out.println("The number you have entered is an
Armstrong number ");
}
else
{
System.out.println("The number you have entered is not an
Armstrong number ");
}

 Print Armstrong number from 100 to 999.

import java.io.*;
class Armstrong2
{
public static void main (String args[])
{
int temp=0;
System.out.println("The armstrong numbers are:");
for(int i=100;i<=999;i++)
{
int num=i,res=0;
while(num!=0)
{
temp = num%10;
res= res + (int)Math.pow(temp,3);
num=num/10;
}
if(res==i)
{
System.out.println(res);
}

}
}
}

2. FIBONACCI SERIES: Fibonacci series i.e. 0 1 1 2 3 5 8 ………… Here numbers


are got by adding previous two numbers. Like 1+1=2, 1+2=3, 2+3=5, 3+5=8 and so
on.
 WRITE A PROGRAM TO PRINT FIBONACCI SERIES

Class Fibo1
{
Public static void main(String args[])
{
System.out.println("Enter the numbers you want to print in Fibonacci
series");
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
int num = Integer.parseInt(br.readLine());
long first=0,second=1,third=0;
System.out.print("Fibonnacci series for "+n+"th number is--");
System.out.println(first+"\t"+second);
for (int i=0;i<num;i++)
{
third=first+second;
System.out.print("\t"+third);
first=second;
second=third;
}
}
}
3.PERFECT NUMBER: A perfect number is a special type of number that is equal
to sum of all its divisors (excluding the number itself). For example 6 is a
perfect number.
.
.. 6 = 1+2+3
Where 1,2,3 are divisors of 6.
Similarly 28 is also a perfect number.
.
.. 28 = 1+2+4+7+14
Where 1,2,4,7,14 are divisors of 28.

 Write a program that check a number

You might also like