“Armstrong -Nummer in Java” Code-Antworten

Armstrong -Nummer 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");   
GelatinousMustard

Wie findet man Armstrong -Zahlen 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);
    }
Chathumal Sangeeth

Armstrong -Nummer 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!");
            }


        }
    }
Apoorav agarwal

Ähnliche Antworten wie “Armstrong -Nummer in Java”

Fragen ähnlich wie “Armstrong -Nummer in Java”

Weitere verwandte Antworten zu “Armstrong -Nummer in Java” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen