Java Reference
In-Depth Information
if (num1 != 0 && num2 != 0)
System.out.printf("%.2f\n",
Math.sqrt(Math.abs(num1 + num2 + 0.0)));
else if (num1 != 0)
System.out.printf("%.2f\n", Math.floor(num1 + 0.0));
else if (num2 != 0)
System.out.printf("%.2f\n",Math.ceil(num2 + 0.0));
else
System.out.println(0);
}
}
a. What is the output if the input is 12 4 ?
b. What is the output if the input is 3 27 ?
c. What is the output if the input is 25 0 ?
d. What is the output if the input is 0 49 ?
13. Consider the following methods:
public static int secret( int x)
{
int i, j;
7
i = 2 * x;
if (i > 10)
j = x / 2;
else
j = x / 3;
return j - 1;
}
public static int another( int a, int b)
{
int i, j;
j = 0;
for (i = a; i <= b; i++)
j = j + i;
return j;
}
What is the output of each of the following program segments?
x = 10;
System.out.println(secret(x));
a.
x = 5; y = 8;
System.out.println(another(x, y));
b.
Search WWH ::




Custom Search