write my assignment 8894

Write the output produced when the Java method declared in each of the following program segments is invoked. Assume that all necessary declarations (like a main method) are in place to produce proper output.

(a) // Method Defintion

public static int compare (int x, int y) {

if (x > y) return 1;

else if ( x < y) return -1; else return 0;

} // end compare … .

// Following are done in main

int value1 = compare (3, 5); int value2 = compare (5, 5); int value3 = compare (7, 5);

System.out.println (“Results are:” + ” ” + value1 + ” ” + value 2 + ” ” + value 3);

(b) // Method Definition

public static void mystery (int x, int y) {

double result = (x + y) / (x – y); System.out.println (“Result is: ” + result);

} // end mystery … .

// Following are done in main

mystery (10, 5);

mystery (6, 5); 

 
"Not answered?"
Get the Answer