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 :: java char array to string 
Java :: spring websocket allow origin 
Java :: radio button android:inputType 
Java :: random number generator java with range 
Java :: java how to define a function 
Java :: arraylist input from user java 
Java :: java wait(timeout) 
Java :: login and logout react native and firebase 
Java :: android studio change button color programmatically 
Java :: how to add chips dynamically android 
Java :: how to reverse a string in java without function 
Java :: set look and feel system default java 
Java :: java stream loop 
Java :: get element in arraylist java 
Java :: Binary tree using linked list in Java 
Java :: java sort a Map by keys reverse descending order 
Java :: jsonArray to list in java 
Java :: @crossorigin spring allow all 
Java :: pyramid pattern program in java 
Java :: java stringbuilder 
Java :: java remove map 
Java :: how to sum a 2d array in java 
Java :: richest customer wealth leetcode 
Java :: equals ignore case java 
Java :: java search arraylist 
Java :: how to change custom font to bold italic in java 
Java :: Looping Through Array Elements Java 
Java :: java check if property exists in class 
Java :: how to check if a person pressed a buuton in jframe 
Java :: comparacion de strings java 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =