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

242
Views
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 answers
Answer question

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 Report

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 Report

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 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!