Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
This is my program for finding armstrong number
package armstrong;

import java.util.Scanner;

public class armstrong {
    static int tr;
    static double tri=0;


    public static void main(String[] args) {
        System.out.println("enter a number");
         int s;
        Scanner sc = new Scanner(System.in);
        s=sc.nextInt();
        int b=s;


        do
        {   
            tr=s%10;
            tri=tri+Math.pow(tr,3);
            s=s/10;


        }
        while(s!=0);
            if(tri==b)
            System.out.println("the number is armstrong");
            else
                System.out.println("not armstrong");

    }

}

here i introduced a variable 'b' because 's' will get modified during the do while loop. is there any way to use 's' rather than storing the value to another variable

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use this program to get Armstrong number:

import java.util.Scanner;

class ArmstrongNumberChecker {
    public static void main(String[] args) {
        int c = 0, a, temp,n;
        System.out.print("enter a number:");
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        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");
        }
    }
}
over 4 years ago · Santiago Trujillo Denunciar

0

Yes there is. Do the following:

tr = s;

do
{   
    tri=tri+Math.pow(tr%10,3);
    tr=tr/10;
}
while(tr!=0);

And then,

if(tri==s)
    System.out.println("the number is armstrong");
else
    System.out.println("not armstrong");

Notice, I directly used tr%10 in the computation for this.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda