// Zorah Fung // This illustrates the syntax of parameters public class Parameters { public static void main(String[] args) { int anotherVariable = 100; favoriteNumber(42); favoriteNumber(365); favoriteNumber(6 + 7 / 2); // Can pass any expression that evaluates to an int favoriteNumber(anotherVariable); favoriteNumber(anotherVariable + 10); // The following won't compile. Must pass exactly one int // favoriteNumber(); // favoriteNumber(5.3); methodTheTakesMultipleParameters(5, 6, 18); methodTheTakesMultipleParameters(2, anotherVariable, 1 + 4); // The following won't compile. Must pass exactly three ints // methodTheTakesMultipleParameters(1, 2); // methodTheTakesMultipleParameters(1, 2, 3, 4); // methodTheTakesMultipleParameters(1, 2, 3.0); } public static void favoriteNumber(int number) { // This parameter is like saying // int number = initialize this to whatever the caller gives me; System.out.println("My favorite number is " + number); } // Note: single letter parameter names are usually bad style since they aren't descriptive! public static void methodTheTakesMultipleParameters(int a, int b, int c) { System.out.println("The first value given to me is: " + a); System.out.println("The second value given to me is: " + b); System.out.println("The third value given to me is: " + c); } }