Write a program to check weather number is Armstrong or not
Program without using user input (Scanner Class):
public class ArmstrongNumber {
public static void main(String[] args) {
int c=0,a,temp;
int n=153;//It is the number to check armstrong
temp=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a);
}
if(temp==c)
System.out.println("armstrong number");
else
System.out.println("Not armstrong number");
}
}
Output :
Program using user input (Scanner Class):
public class ArmstrongNumber {
public static void main(String[] args) {
int c=0,a,temp;
int n;
System.out.println("Enter the number");
Scanner scanner=new Scanner(System.in);
n=scanner.nextInt();
temp=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a);
}
if(temp==c)
System.out.println("this number is armstrong number");
else
System.out.println("this number is not armstrong number");
}
}
Output :
-Important Programs for Freshers
- Palindrome Number
- Prime Number
- Swapping Number
- Leap Year
- Odd and Even Number
- Fibonacci Series
- Factorial Number
- Print Table
Sorting and Searching Programs
Learn Pattern Programs
- Alphabet
pattern program in java
- Star Pattern Programs in Java
- Square
pattern programs in java
- Diamond
Star pattern programs in java
- Number
Pattern Programs in java
- Diagonal
pattern program in java
Click to learn Array Programs
- 4
ways to print Array in Java
- 2D
Array in Java
- Anonymous
Array in Java
- Single
Dimensional Array in Java
- Find
Second Largest Number in Array
- Delete
an Element in Array in Java
- Common
Element in Array in Java
- Missing
Element in Array
- Insert
Element in Array
- Reverse Array in Java
- Merge Two Array in Java
- Smallest
and Largest Elements in Array
- Find
Odd and Even Number in Array
Click to Learn
MySQL
No comments:
Post a Comment