Java Program #11 - Find Armstrong Number in Java

preview_player
Показать описание
Java Program to find Armstrong Number in java
In this video by Programming for Beginners we will learn to write Java Program for Armstrong Number, using Java Tutorial videos.
This Java program is very important for your Java interview questions or if you are learning Java Programming language as a student.

An Armstrong number is a positive m-digit number that is equal to the sum of the mth powers of their digits.

Examples:
1: 1^1 = 1
2: 2^1 = 2
3: 3^1 = 3
153: 1^3 + 5^3 + 3^3 = 1 + 125+ 27 = 153
125: 1^3 + 2^3 + 5^3 = 1 + 8 + 125 = 134 (Not an Armstrong Number)
1634: 1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1643

1741725 is an Armstrong Number.

==========

Java Tutorial for Beginners Playlist:

All Java Programs Playlist:

We can learn Java Programming language to make web applications or mobile applications for android phones and several other applications for windows, Mac OS and Unix operating systems. Also we can make android applications using Java programming. The concepts covered will be related to basic java and core java that will help you in your next interview questions. You can use any version of Java but all concepts will be same for all java versions. I will be using Java SE 8.
Java is a high-level programming language. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.
Java is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Software Development Domain.

Java JDK:
Eclipse IDE:

YouTube Gears:

#JavaProgram #JavaTutorial #Programming #Java

============================
LIKE | SHARE | COMMENT | SUBSCRIBE

Thanks for watching :)
Рекомендации по теме
Комментарии
Автор

All JAVA Programs Playlist:
Java Tutorial Playlist:

programmingforbeginners
Автор

bro really thank for teaching it properly it was asked in aptitude test but i was blank in the test i will start learning properly with ur vedios

shashanksanji
Автор

I think this one is the best way to solve and nice explanation....it would be help to crack the interview... thank you so much sir for understanding nicely 👌🥰🙏

diptimayeepatro
Автор

bhai you earned a subscriber, hats off bro, may god bless you

abhijit
Автор

thank you bro for clearing my doubts ❤

thenameis-jatin
Автор

Can you please tell what is the time complexity and space complexity for this solution

nagamanim
Автор

Bro, I m getting error that " Sum cannot resolved to be variable'

crazzyraghu
Автор

tried without while loop..this is working fine for me (give any number within the limit of integer data type)

Scanner sc=new Scanner(System.in);

System.out.println("Enter any number to find out if it is a Armstrong number or not");

int input=sc.nextInt();

String s="";
String count=s.valueOf(input);
int input_size = count.length();
int digit;
double Armstrong=0;
double result=0;
int actual=input;

if(input>0)
{

for(int i=1;i<=input_size;i++)
{
digit=actual%10;
actual=actual/10;

result=Math.pow(digit, input_size);

}

if(input==Armstrong)
{
System.out.println("Given number is armstrong");
}
else
{
System.out.println("Given number is not armstrong");
}
}
else
{
System.out.println("Given number is not armstrong");
}

abdulrahim
Автор

Nice video bro
Please simplify the code

reddybasha
Автор

public static void main(String[] args) {
int n=407;
int orginal_number=n;
int sum=0;
int
while(n>0){
int digit= n%10;
n=n/10;
sum= (int) (sum+Math.pow(digit, numOfdigits));
}
if (sum==orginal_number){
is the Armstrongnumber");
}else {
is not a Armstrongnumber");
}
}

pavankumar
Автор

public static void main(String[] args) {

int number;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number : ");
number = sc.nextInt();
System.out.println("Is amstrong num ; " + isAmstrong(number));
}

static boolean isAmstrong(int n) {
int digits, temp;
temp = n;
while(temp > 0) {
temp = temp/10;
digits++;
}
System.out.println("No of digits: " + digits);

temp = n;
while(temp> 0) {
int lastDigit = temp %10;
sum = (int)(sum +Math.pow(lastDigit, digits));
temp =temp/10;


}
System.out.println("sum is ; " + sum);

if(sum == n)
return true;

return false;
}


}

Receiving error that sum cannot resolved to a Variable

crazzyraghu