I have a problem with this exercise in java

0

The problem is the following:  Create a class called MyMethods, which must contain 2 methods, one of type void and another that returns value, the latter must have a parameter. The first method should print the message "Hello Happy day" and the second method should be sent as an argument the message "Thank you very much". You must invoke each method from the class that has the Main method.

I have developed a bit but I no longer understood I only did this: I do not know if it's haci

public void mensaje1()
{
   System.out.println("hola feli dia");

   public String mensaje2(String cadena)
   {
     return cadena;
   }

}

class demomimetodo{

public static main(String args 
public static void main (String agrs[]) 

}
    
asked by sstan 07.11.2017 в 21:01
source

1 answer

0

Your question / doubt is not clear, but I will try to help you.

If I understood your situation well, the code would be the following:

class Main:

public class Main {

    public static void main(String[] args) {

        // Hago una instancia de la clase "MisMetodos"
        MisMetodos instancia = new MisMetodos();

        // Llamo al "metodo1" para que imprima el mensaje "Hola Feliz Dia"
        instancia.metodo1();

        // Llamo al "metodo2" enviandole un mensaje como argumento para que lo imprima
        instancia.metodo2("Muchas gracias igualmente");
    }

}

public class MisMetodos:

public class MisMetodos {

    // "metodo1" tipo void, no recibe parametros
    public void metodo1() {
        System.out.println("Hola Feliz Dia");
    }

    // "metodo2" tipo void, recibe un String como parametro
    public void metodo2(String parametro) {
        System.out.println(parametro);
    }

}

The output of this code is:

  

Hello Happy Day

     

Thank you very much also

I hope I have helped you with your problem, if it is the case, do not forget to select my comment as the Accepted Answer.

Greetings.

    
answered by 07.11.2017 / 22:01
source