“Numéro Armstrong en Java” Réponses codées

Numéro Armstrong en 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

Comment trouver des numéros Armstrong en 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

Numéro Armstrong en 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

Réponses similaires à “Numéro Armstrong en Java”

Questions similaires à “Numéro Armstrong en Java”

Plus de réponses similaires à “Numéro Armstrong en Java” dans Java

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code