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

531
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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