java does not know how to handle the object

0
 static int n=Integer.parseInt(JOptionPane.showInputDialog(null,"introduzca 
 un 
 numero para verificar si es primo"));

public boolean calcularNumero(int dividendo,int divisor,int aux) {       
//cocientes,calcular numero primo,dudas con divisor

        int dividendo1=aux;
        divisor=dividendo;
        aux=divisor;
        int numero3=dividendo/divisor;
        if (numero3==divisor && numero4==divisor) {
            return primo=true;
        }
            else    if (numero3==aux && numero4==aux) {
                return primo=true;


            }


    return primo;

}

public boolean esPrimo(int n) {
    for(int i=2;i<n;i++) {
        if(n%i==0)
            return false;
    }
    return true;
}

   public static void main(String[] args) {

    Scanner ent = new Scanner(System.in);
    Arrays_aelatorio arra=new Arrays_aelatorio();
    arra.esPrimo(n);
    System.out.println("el valor del numero para saber si es primo"+arra);

// the output on the screen is the following one @ followed by numbers // the value of the number to know if it is primohola.Arrays_aelatorio@323b36e0

    
asked by oshju 17.06.2018 в 15:06
source

2 answers

2

If you take it out in that format, it is possible that you are printing the address in memory of what you are trying to print. What you have to do is include the toString () method to your object. This way, when you want to print it on the screen, this method will automatically be called and it will print what you specify there.

Here is your example. As you can see, it is public and you can return and do whatever you want inside it. I gave you several examples of the commented return.

public String toString(){
   return "Este array es primo";
   //return variable;
   //return "nombre: "+variable;
}
    
answered by 17.06.2018 в 15:23
0

In effect, what you are doing is printing the position in the Array's memory.

If what you want is to print the elements of the Array, what you should do is go through a loop for each of its positions and in turn print them with System.out.println ().

Something like this, more or less:

Array array = new Array();
for(int i=0; i<array.length(); i++){
   System.out.println(array[i]);
}
    
answered by 17.06.2018 в 20:43