Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
este es mi programa para encontrar el numero de armstrong
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"); } }

aquí introduje una variable 'b' porque 's' se modificará durante el ciclo do while. ¿Hay alguna forma de usar 's' en lugar de almacenar el valor en otra variable?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede usar este programa para obtener el número de Armstrong:

 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 Report

0

Sí hay. Haz lo siguiente:

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

Y luego,

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

Tenga en cuenta que utilicé directamente tr%10 en el cálculo para esto.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!