Java program to check prime number : find prime number in Java
Java program to remove duplicate elements from an array
Java program to check if string is a palindrome : check palindrome string in java
Java Program to check whether number is Palindrome or not | Java Find Palindrome Number
Syntax Error In JavaScript In Hindi | JS SyntaxError
Web developer roadmap : How to become web developer ? web development kya hai ?
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
वो numbers जिसमे हर digit के cubes का total उस number के बराबर होता है , उन्हें Armstrong numbers कहते हैं।
Image on pixabay
कुछ Armstrong Numbers इस प्रकार हैं -
1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834 ये सभी Armstrong numbers हैं।
सबसे पहले ऊपर दिए गए numbers को check कर लेते हैं कि ये number Armstrong हैं या नहीं। तो जैसा कि अभी आपने ऊपर पढ़ा कि अगर number , इसमें present हर digit के cubes के total के बराबर होना चाहिए।
11 = 1 21 = 2
इसी तरह से 153 , हालाँकि इसमें 3 digit हैं इसीलिए हर digit पर 3 की घात होगी।
33 = 27 73 = 343 00 = 0 Total : 27 + 343 +0 = 370
इस article में Java language में हम Armstrong number check करने के लिए एक program बनाएंगे।
// import package.
import java.util.*;
public class ArmstrongNumber {
public static boolean isArmstrong(int num)
{
int originalNum, remainder, n = 0, result = 0;
originalNum = num;
for (;originalNum != 0; originalNum /= 10, ++n);
originalNum = num;
for (;originalNum != 0; originalNum /= 10)
{
remainder = originalNum % 10;
result += Math.pow(remainder, n);
}
if(result == num)
return true;
else
return false;
}
public static void main(String[] args) {
// get number from user number.
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int num = sc.nextInt();
// now call function.
boolean result = isArmstrong(num);
if(result)
System.out.println(num + " is an Armstrong number.");
else
System.out.println(num + " is not an Armstrong number.");
}
}
Output :
Enter a number: 370 370 is an Armstrong number. Enter a number: 9 9 is an Armstrong number. Enter a number: 10 10 is not an Armstrong number.
Loading ...
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook