Armstrong Number Program In Java

Java program to find Armstrong number. Here this is a simple and quick Armstrong number program. This Armstrong number program in java I have tried to make sorter.  As who are aware of this Armstrong number example, they all know that this is the number game program.

Program for Armstrong number in java

Such as my previous article to find palindrome number in java, reverse number, the sum of minimum and maximum and similarly getting the repeated number. And also I have composed some various different program related java. I have received positive comment related all this.  So amount them one visitor has asked me regarding this to Armstrong number program in java.

 

So in respect to this, I have tried to design this simple program simpler. And hare also I am going to introduce you two program to get Armstrong in java. I have people asking the question like:-

  • 4 digit Armstrong number in java
  • Armstrong number in java using function
  • Armstrong number in java between 1 to 1000
  • Algorithm for Armstrong number in java
  • What is logic of Armstrong number in java
  • Palindrome and Armstrong number in java

Armstrong number program in java begin here

So here users are going to get the answer of all above question. All upper questions are similar in java program for Armstrong number. Only a few things are making different to each other. To making simpler this java program to find Armstrong number here am going to use java function.

Java program to find Armstrong number                Download       

1 import java.util.*;
2 public class arm1
3 {
4 static int arm(int x, int count)
5 {
6 int sum=0;
7 for (int i=0; i<count; i++)
8 {
9 int reminder=x%10;
10 int pass=x%10;
11 for (int j=0; j<count-1; j++)
12 {
13 int multi=pass*reminder;
14 pass=multi;
15 }
16 sum=sum+pass;
17 x=x/10;
18 }
19 return(sum);
20 }
21 static void condition(int x, int y)
22 {
23 if (x==y)
24 {
25 System.out.println(“This is Armstrong number :: “+x);
26 }else
27 {
28 System.out.println(“This is not Armstrong number ::  “+x);
29 }
30 }
31 public static void main(String[] args)
32 {
33 System.out.print(“Enter some value to check :: “);
34 Scanner input=new Scanner(System.in);
35 int x=input.nextInt();
36 System.out.println();
37 String con=Integer.toString(x);
38 int length=con.length();
39 int a=arm(x, length);
40 condition(x, a);
41 }
42 }

Armstrong number program in java Second

Java program to find Armstrong number                             Download   

1 import java.util.*;
2
3 public class Arm
4 {
5
6
7 public static void main(String[] args)
8 {
9 Scanner input=new Scanner(System.in);
10 int f1=input.nextInt();
11 int f8=f1;
12 int l1=String.valueOf(f1).length();
13 int l2=l1-1;
14 int l3=l1-2;
15 int sum1=0;
16 int sum=0;
17 int f4=0;
18 while (f1>0)
19 {
20 int f2=f1%10;
21 int f5=f2;
22 int f6=f2;
23 for (f4=0; f4<l2; ++f4)
24 {
25 f5=f5*f2;
26 sum+=f5;
27 }
28 for (f4=0; f4<l3; ++f4)
29 {
30 f6=f6*f2;
31 sum1+=f6;
32 }
33 f1=f1-f2;
34 int f3=f1/10;
35 f1=f3;
36
37 }
38 //System.out.println(“This is :: ” +sum);
39 //System.out.println(“This is :: ” +sum1);
40 int total=sum-sum1;
41 //System.out.println(“This is :: ” +total);
42 if (total==f8)
43 {
44 System.out.println(“This is Armstrong number ::” + ” “+f8);
45 }else
46 {
47 System.out.println(“This is not Armstrong number ::” + ” “+f8);
48 }
49 }
50 }

Program for Armstrong number in java:- Final comment

In the above-designed program, if you get any difficulty so let me know by a below-commenting box that I can come up with the right solution to make you understand regarding Armstrong number. Above listed all both program I have tried harder to make it simpler.

Similarly like my previous java program in this program also I have used some of the useless variables to make you a better understanding.

In case if you have any questions in your mind so let me know and most important things if users have any others regarding any others Jave program which is not mandatory to questions are related with the article. So let’s get Armstrong number example.

Speak Your Mind

*

error: Content is protected !!
DMCA.com Protection Status