Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

exmple of methods in java

class Main {

  // method with no parameter
  public void display1() {
    System.out.println("Method without parameter");
  }

  // method with single parameter
  public void display2(int a) {
    System.out.println("Method with a single parameter: " + a);
  }

  public static void main(String[] args) {
    
    // create an object of Main
    Main obj = new Main();

    // calling method with no parameter
    obj.display1();
    
    // calling method with the single parameter
    obj.display2(24);
  }
}
Comment

exmple of methods in java

class Main {

// create a method
  public static int square(int num) {

    // return statement
    return num * num;
  }

  public static void main(String[] args) {
    int result;

    // call the method
    // store returned value to result
    result = square(10);

    System.out.println("Squared value of 10 is: " + result);
  }
}
Comment

exmple of methods in java

class Main {

  // create a method
  public int addNumbers(int a, int b) {
    int sum = a + b;
    // return value
    return sum;
  }

  public static void main(String[] args) {
    
    int num1 = 25;
    int num2 = 15;

    // create an object of Main
    Main obj = new Main();
    // calling method
    int result = obj.addNumbers(num1, num2);
    System.out.println("Sum is: " + result);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: Java double Keyword 
Java :: intellij disable welcome screen 
Java :: setsystemuivisibility example 
Java :: pen default Mail Application in android studio java 
Java :: how to get map with string as key and Arraylist as value in java 
Java :: pioneer meaning 
Java :: how good at you are at java 
Java :: toSet 
Java :: why is button hover not working in java netbeans 
Java :: jdk 17 not showing in update alternatives 
Java :: play default message ringtone android studio 
Java :: java.util.concurrent.CancellationException showing in suggestion 
Java :: java linkedlist 
Java :: java byte array to blob 
Java :: java bufferedreader 
Java :: swapping techniques using java 
Java :: extend vs implement in java 
Java :: java graph 
Java :: string formatting java 
Java :: java hello world program 
Java :: update role spring security 
Java :: java font bold italic 
Java :: how do I test the reverse method in java using jest 
Java :: java read from connection even if 404 
Sql :: select nls_date_format 
Sql :: oracle get table schema 
Sql :: Enter into postgresql database,create user and grant Access 
Sql :: sqlalchemy_database_uri for mysql 
Sql :: sql server find table name 
Sql :: oracle kill session by username 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =