DEV Community

Arshad Ali
Arshad Ali

Posted on

JAVA-Methods

import  java.util.ArrayList;

public class Main {

            public static void main(String[] args) {

    //method = a block of code that is executed whenever it is called upon

            String name = "Bro";
            int age = 21;

            hello(name, age);

        }

            static void hello(String name, int age) {
                System.out.println("Hello "+name);
                System.out.println("Hello "+age);
            }
}
Enter fullscreen mode Exit fullscreen mode

Second Methods

import  java.util.ArrayList;

public class Main {

            public static void main(String[] args) {

    //method = a block of code that is executed whenever it is called upon

            int x = 3;
            int y = 4;

            int z = add(x,y);

            System.out.println(z);

        }

            static int add(int x, int y) {
                int z = x + y;
                return z;
     }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)