// Whitaker Brand // CSE142 // TA: Suraj // Section: QQ // // This program demonstrates simple parameter usage. // Our printY method takes in information at call time // (on line 13) -- we must now pass an int in order to call // printY. public class ParameterExample { public static void main(String[] args) { int x = 5; System.out.println("Here in main, x = " + x); // To get data (like the value of the variable x) into a method, // we pass that information as a parameter. printY(x); // Note, we don't have to pass a variable, we can pass any int -- // literals: (17), expressions: (4 + 6), variables: (x), printY(17); // or even very complex expressions: // as long as it evaluates to an int, we're good printY(x * x / (4 % 3) + 2 - x + 17 % 5); // The type of the variable in the header of printY // is what determines thet type of data that can be passed in: // for this program, only ints // no doubles: this won't work // printY(4.5); // no strings: this won't work // printY("5"); // also, we MUST pass an int: this won't work // printY(); } // Prints a message with the value of the given parameter public static void printY(int y) { // Note that here in this method, that same number (5, 17) // has a different name than it does in main. // What is passed into this method is a number, not a variable System.out.println("Here in printY, y = " + y); } }