Java Reference
In-Depth Information
public static void traceMe( double x, double y)
{
double z;
if (x != 0)
z = Math.sqrt(y) / x;
else
{
System.out.print("Enter a nonzero number: ");
x = console.nextDouble();
System.out.println();
z = Math.floor(Math.pow(y, x));
}
System.out.printf("%.2f, %.2f, %.2f, %n", x, y, z);
}
}
a. What is the output if the input is 3 625 ?
b. What is the output if the input is 24 1024 ?
c. What is the output if the input is 0 196 ?
29. In Exercise 28, determine the scope of each identifier.
30. Write the definition of a void method that takes as input a decimal number
and outputs 3 times the value of the decimal number. Format your output
to two decimal places.
31. Write the definition of a void method that takes as input two decimal
numbers. If the first number is nonzero, it outputs the second number
divided by the first number; otherwise, it outputs a message indicating that
the second number cannot be divided by the first number because the first
number is 0.
32. Write the definition of a method that takes as input two parameters of type
int , say sum and testScore . The method updates the value of sum by
adding the value of testScore , and then returns the updated value of sum .
PROGRAMMING EXERCISES
1. Write a value-returning method, isVowel , that returns the value true if a
given character is a vowel, and otherwise returns false . Also write a
program to test your method.
2. Write a program that prompts the user to input a sequence of characters
and outputs the number of vowels. (Use the method isVowel written in
Programming Exercise 1.)
3. Write a program that uses the method sqrt of the class Math and outputs
the square roots of the first 25 positive integers. (Your program must output
each number and its square root.)
 
Search WWH ::




Custom Search