Show in cosola data of an array in Java [closed]

-1

I want to extract and show in the console the data of a person in an array in Java that contains several repeated data like these: dni "Compound Name", "Surnames" and date. And that shows in a line the ID, in another line the name composed in capital letters and a blank space between the words, another line with the surnames in capital letters and a blank space separating them and another with the date in format yyyy / mm / dd.

An example from this, that I do not know if it is correct:

 double[][] matriz={{22456789L, "Jose Tomas", "Gonzalez Alcantara", 22/08/1972},{22456789L, "Luis jose", "Alcantara Perez", 02/02/1932}};
    
asked by Juan 15.10.2016 в 20:05
source

2 answers

1

The Proposal Line as an example is poorly thought out as close as it could be so it would be an Arrangement of String

String[][] personas = new String[][]
    { {"12345678","Nombre1 Apellido1","2016/10/12"}, 
      {"99999999","Nombre2 Apellido2","2015/10/12"}
    };

For such task I propose to use clases with the respective attributes that it raises detail a basic example, to try and create Objects

public class Person {

  /* Atributos */
  private String dni;
  private String nombre;
  private String apellido;
  private String fecha;

  /* Contructores */
  public Person() {
  }

  public Person(String dni, String nombre, String apellido, String fecha) {
      this.dni = dni;
      this.nombre = nombre;
      this.apellido = apellido;
      this.fecha = fecha;
  }

  /* Aquí irían sus getter y setters */

  /* Método toString */
   public String toString() {
    /* \n para el salto de línea y toUpperCase() para mostrar en mayúsculas */
    return "DNI : " +dni +"\n"+
            "Nombre : "+ nombre.toUpperCase() +"\n"+
            "Apellido : "+ apellido.toUpperCase() +"\n"+
            "Fecha  : " +fecha+"\n";
   }

In your Main class, you should create a arreglo of Objects of type Person and the impression would be by a for of objects by calling the method toString();

 public static void main(String[] args)  {
  Person[] personas = new Person[2]; /* Arreglo de Objetos*/
   /* Llamo al Constructor con Parametros */
  personas[0]= new Person("12345678", "nombre1", "apellido1", "2014/12/12");
  personas[1]= new Person("98765432", "nombre2", "apellido2", "2014/02/06");

    for (Person persona : personas) {
        /* LLamamos al Método toString(); de la clase Person*/
        System.out.println(persona.toString());
    }

}
    
answered by 15.10.2016 / 22:35
source
1

To print new line you use the escape character \ n, and to print with space, you simply make a concatenation of an empty character.

  

System.out.println (array [pos] + "" + array [pos] + "\ n");

Do not forget to cycle through the array.

    
answered by 15.10.2016 в 20:12