package CIS115; public class Parameters { //methods with main need to be marked static public static void doSomething(int a, String str, double b) { int x = 2 * a; double y = (3 * b); System.out.println(str + " " + (x + y)); } public static void pr(int a, String str, double b) { int x = 2 * a; double y = (3 * b); System.out.println(str + " " + (x + y)); } public static void method1(int x, int y, int z) { System.out.println(x + " " + y + " " + z); x = y + z; y = 10; z = y; } public static void method2(int[] list, int x) { x = 10; list[0] = 10; } public static void even(int num) { if (num % 2 == 0) { System.out.println("even"); } else { System.out.println("odd"); } } public static void repeater(String word, int times) { for (int i = 0; i < times; i++) { System.out.println(word); } } public static void main(String[] args) { // calling methods with literals System.out.println("doSomething(5, \"Java\", 5.5);"); doSomething(5, "Java", 5.5); System.out.println("-----\n"+"pr(1, \"hello\", 2);"); pr(1, "hello", 2); System.out.println("-----\n"+"pr(2, \"goodbye\", 1);"); pr(2, "goodbye", 1); // calling methods with variables int z = 3; int a = 4; String s = "words"; System.out.println("-----\n"+"pr(z, s, a);"); pr(z, s, a); System.out.println("-----\n"+"pr(a, s, z);"); pr(a, s, z); // java is call by value, these variables are not changed int q = 55; int r = 22; System.out.println("-----\n"+"before method 1: q="+ q + " r=" + r); System.out.println("-----\n"+"method1(1, q, r);"); method1(1, q, r); System.out.println("-----\n"+"method1(q, r, q + r);"); method1(q, r, q + r); System.out.println("-----\n"+"method1(q, q, q);"); method1(q, q, q); System.out.println("-----\n"+"after method 1: q="+ q + " r=" + r); // call by value means we pass the int var, so // the method can change the values in the array int[] list = new int[]{2, 4, 6, 8, 10}; int y = 4; System.out.println("-----\n"+"before method 2: list[0]="+ list[0] + " y=" + y); method2(list, y); System.out.println("after method 2: list[0]="+ list[0] + " y=" + y); System.out.println("-----\n"+"even(828);"); even(828); System.out.println("-----\n"+"even(829);"); even(829); System.out.println("-----\n"+"repeater(\"hello\", 9);"); repeater("hello", 9); System.out.println("-----\n"+"repeater(\"xyz\", 5);"); repeater("xyz", 5); } }