Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

armstrong number in java

 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");   
Comment

how to find armstrong numbers in java

    public static void printArmstrongOrNot(int num) {
        int temp = num;
        int cubeValue = 0;
        while (num != 0) {
            cubeValue += (num % 10) * (num % 10) * (num % 10);
            num /= 10;
        }
        if (cubeValue == temp) {
            System.out.println(temp + " is an armstrong number");
        } else {
            System.out.println(temp + " is not an armstrong number");
        }

    }

    public static void main(String args[]) {
        printArmstrongOrNot(371);
        printArmstrongOrNot(372);
    }
Comment

Armstrong Number in Java

// program to print an Armstrong Number by taking user input.

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int no = sc.nextInt();
        int t1 = no;
        int length = 0;
        while (t1 != 0) {
            length = length + 1;
            t1 = t1 / 10;

        }
        int t2 = no;
        int arm = 0;
        int rem;
        while (t2 != 0) {

            int mul = 1;
             rem = t2 % 10;
            for (int i = 1; i <= length; i++) {
                mul *= rem;
            }
            arm = arm + mul;
            t2 /= 10;
            if (arm == no) {
                System.out.println(no+ " Is an Armstrong Number !");
            } else {
                System.out.println("Non an Armstrong Number!");
            }


        }
    }
Comment

PREVIOUS NEXT
Code Example
Java :: initilize an array java 
Java :: java array get index 
Java :: traversing treemap in java 
Java :: how to convert iso-8859-1 to utf-8 in java 
Java :: java calendar 
Java :: R8: java.lang.OutOfMemoryError: GC overhead limit exceeded react-native 
Java :: Arraylist in java by dc 
Java :: Java Access PriorityQueue Elements 
Java :: how to add arms to armor stands 1.16 Java Edition 
Java :: mongodb check if field exists java 
Java :: build libgdx jar 
Java :: max int array java 
Java :: android studio hide linearlayout 
Java :: finding length of arrays in java 
Java :: infinite value total 
Java :: java calcuate milliseconds since 1970 
Java :: how to run a java file in terminal 
Java :: transparent card background android 
Java :: java bogosort 
Java :: java stream map int to char 
Java :: arraylist remove name in java 
Java :: Implementing the Stack Class in java list 
Java :: vue input pre initial value 
Java :: change brightness of image in java 
Java :: Read json url in android - NAYCode.com 
Java :: what is object in java 
Java :: java list of lists 
Java :: fix nullpointerexception 
Java :: java list of a class has a string that is equal to 
Java :: procedure java 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =