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

236
Vistas
How do I display numbers in octal notation in java?

I need to write a code for a project and part of the code needs to be able to do as follows: Generate one random positive integer from 1 to 100, and then display all of the numbers in octal notation from 1 to the random integer.

Can someone please help me with this? (only the octal notation part)

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

0

You can print numbers in octal notation using the printf method with the %o formatter:

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

0

You can use Random.nextInt() for random number and Integer.toOctalString() for octal conversion.

Try this out.

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 Denunciar

0

1st generate a random number:

int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1); // in your case min=1 and max=100;

and to convert above number to octal you can use toOctalString method.

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