Eager to Code, Enjoy to Debug ~ Embark into Each Stage with Your Heart

Chapter 7: Arrays (Exercise 7.13)

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[] = new int[arrayLength]; // create array

// get initial value and increment from command-line argument
double initialValue = Double.parseDouble(args[1]);
double increment = Double.parseDouble(args[2]);

// sum the double values passed by the command-line arguments
for(int counter:array)
initialValue+=increment;
System.out.println(initialValue);
} // end main
} // end class SumDouble

1 Response to "Chapter 7: Arrays (Exercise 7.13)"

Hi, your codes have been so helpful with my course work and I am just wondering if you have any additional codes for the remaining chapter 7 arrays.
I am truly struggling with this at this point and would be so happy if you would post some more.
Thanks in advance.
Keith

PS if you have more available I would appreciate it so much if you could email them to his_anointed@live.com as well.

Leave a Reply

Friday’s Java Snack


In Java, "thread" means:

  • An instance of class java.lang.Thread
  • A thread of execution


An instance of Thread is just an object that has variables and methods, and lives and dies on the heap.
 
A thread of execution is an individual process that has its own call stack (one thread per call stack).

 

May 2009
M T W T F S S
« Apr   Jun »
 123
45678910
11121314151617
18192021222324
25262728293031

Archives


  • system_forex_: I like this website very much. This is such a outstanding web. And it is not like other money oriented website, the message here is genuinely impo
  • Faruk: its very very very fine solution perfect
  • blackhawk: Nice tip -- thanks for sharing

StatCounter

free hit counters