Armstrong Number
Armstrong Number
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
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 ");
}
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);
}
}
}
}
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.