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

235
Views
¿Cómo muestro números en notación octal en Java?

Necesito escribir un código para un proyecto y parte del código debe poder hacer lo siguiente: generar un número entero positivo aleatorio del 1 al 100 y luego mostrar todos los números en notación octal del 1 al número entero aleatorio.

¿Puede alguien por favor ayudarme con esto? (solo la parte de notación octal)

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Puede imprimir números en notación octal utilizando el método printf con el formateador %o :

 System.out.printf("Number in octal notation: %o", myNumber);
over 4 years ago · Santiago Trujillo Report

0

Puede use Random.nextInt() para números aleatorios e Integer.toOctalString() para conversión octal.

Probar esto.

 import java.util.Random; public class Main { public static void main(String[] args) { Random random = new Random(); int number = random.nextInt(100) + 1; for(int i = 1; i < number; i++){ System.out.println(Integer.toOctalString(i)); } } }
over 4 years ago · Santiago Trujillo Report

0

Primero generar un número aleatorio:

int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1); // en tu caso min=1 y max=100;

y para convertir el número anterior a octal, puede usar el método toOctalString.

 String myOctNumber = Integer.toOctalString(randomNum); System.out.println("myOctNumber = "+myOctNumber);
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!