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

528
Views
printing random numbers when printing a variable with printf()

I'm trying just to print a simple thing that says : Hola hi hello, but for some reason it is printing what I want but I get some numbers on my output

Sorry if its an easy thing to find or fix but I'm just starting with java so I'm a complete noob.

My files look like:

Example.java

public class Example {
    public static void main(String[] args){

            Hola ho = new Hola("hola");

            System.out.printf("%s hi hello", ho);
    }
}

Hola.java

class Hola {
    public String name;

    public Hola(String name){
        this.name = name;

    }
}

Output: Hola@7852e922 hi hello%

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You have to use ho.name:

System.out.printf("%s hi hello", ho.name);

because ho will print the object reference and not the name.

over 4 years ago · Santiago Trujillo Report

0

You should override the toString() method of your Hola class:

class Hola {
    public String name;

    public Hola(String name){
        this.name = name;

    }
    @Override
    public String toString()
    {
        return this.name;
    }
}
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!