Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda