Posted by: Chyne on: May 23, 2009
/* Exercise 7.13
* 1. Use enhanced for statement
* 2. Sum the double values passed by the command-line arguments.
* 3. Use the static method parseDouble of class Double to convert a String to a double value.
*/
package Exercises;
public class SumDouble {
public static void main(String []args)
{
// get array size from first command-line-argument
int arrayLength = Integer.parseInt(args[0]);
int array[] = [...]
Posted by: Chyne on: May 23, 2009
/* Exercise 7.12
* 1. Size of the array specified by the first command-line argument.
* 2. If no command-line argument is supplied, use 10 as the default size of the array.
*/
package Exercises;
public class SizeOfArray {
public static void main(String[] args) {
// check existence of command-line arguments
if (args.length == 0)
// set default size of array to 10
int array[] [...]
Posted by: Chyne on: May 23, 2009
/* Exercise 7.11
* 1. Calculates the product of a series of integers
* 2. Passed to method product using a variable-length argument list.
* 3. Test the method with several calls, each with a different number of arguments.
*/
package Exercises;
public class CalculateProduct {
// calculate the product
public static int product(int… numbers) {
int product = 1;
// multiply the series of [...]
Posted by: Chyne on: May 1, 2009
/* Exercise 7.8
* 1. Use one-dimensional array
* 2. A company pays its salespeople on a commission basis.
* 3. The salespeople receive $200 per week plus 9% of their gross sales for that week.
* 4. e.g. A salesperson who grosses $5000 in sales in a week receives $200 plus 9% of $5000, or a total of [...]
Posted by: Chyne on: March 1, 2009
/* Exercise 6.34
* 1. Displays a table of the binary, octal, and hexadecimal
* 2. Equivalents of the decimal numbers in the range from 1 to 256.
*/
package Exercises;
public class BiochexTable {
public static void main(String []args)
{
int decimal;
// display message
System.out.println(“Decimal”+”\t”+”Octal”+”\t”+”Hexadecimal”+”\t”+”Binary”);
// for loop to display 1 to 256
for(decimal=1;decimal<=256;decimal++)
{
// convert decimalto octal, hexadecimal and binary
System.out.println(decimal+”\t”+
Integer.toOctalString(decimal)+”\t”+
Integer.toHexString(decimal)+”\t\t”+
Integer.toBinaryString(decimal));
} // end [...]