1public class Main {
2 public static void main(String args[]) {
3 SayHi();
4
5 int sum = AddNums(5, 6);
6 System.out.println(sum);
7 }
8
9 public static void SayHi() { //This method has no return value
10 System.out.println("Hi!");
11 }
12
13 public static int AddNums(int a, int b) { //This method has a return value
14 return a + b;
15}
1package com.company;
2
3public class Main {
4 static void one(){ // youCanPutWhatEverNameYouLikeInThePlaceOf"One"
5 System.out.println("HELLO");
6 }
7 public static void main(String[] args) {
8 one(); //theTerminalShouldSay"HELLO"
9 }
10}
11
1public class Main
2{
3 static void function(){
4 System.out.println("I am a function!");
5 }
6 public static void main(String[] args) {
7 function();
8 }
9}
1//declare a function like this:
2void function(int parameter1)
3{
4 //function body
5}
6//call the function like this:
7function(1);
1public int addNum(int num1, int num2) {
2 total = num1 + num2;
3 System.out.println("Total: " + total);
4}