Methods in Java
Our group presentation on methods
public class Main {
static void ExampleMethod(){ // ExampleMethod is the name of the method; static means that the method belongs to the Main class and not an object
System.out.println("Hi!");
}
}
public class Main {
static void ExampleMethod() {
System.out.println("Hello AP CSA!");
}
public static void main(String[] args) {
ExampleMethod();
}
}
// Outputs "I just got executed!"
Hacks
- Fill in the missing code:
static void myMethod() { System.out.println("I just got executed"); } public static void main(String[] args) { __; }
- Describe what the Method does:
public String myMethod(String s,int i){
String r = '';
for(int j = 0; j < s.length(); j++) {
} return r; }r += (char)(s.charAt(j)+i);