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

Archive for October 11th, 2008

Chapter 5: Control Statements Part II (Exercise 5.14 c)

Posted by: Chyne on: October 11, 2008

/*
* Exercise 5.14 (c)
*/

package Exercises;
public class Asterisks_c {
public static void main(String[] args) {
// initialization phase (row and column)
int i;
int j;
// loop for row
for (i = 10; i >= 1; i–) {
System.out.println();
// loop for spaces
for (int k = 10; k > i; k–) {
System.out.print(‘ ‘);
} // end for loop for spaces
// loop for [...]

Chapter 5: Control Statements Part II (Exercise 5.14b)

Posted by: Chyne on: October 11, 2008

/*
* Exercise 5.14 (b)
*/
package Exercises;
public class Asterisks_b {
public static void main(String[] args) {
// initialization phase (row and column)
int i;
int j;
// loop for row
for (i = 10; i > 0; i–) {
// loop for column
for (j = 0; j < i; j++) {
// print asterisks side by side
System.out.print(‘*’);
} // end for [...]

Chapter 5: Control Statements Part II (Exercise 5.14a)

Posted by: Chyne on: October 11, 2008

/* Exercise 5.14 (a)
* 1. Use a for loops to generate the patterns.
* 2. All asterisks (*) should be printed by a single statement of the form System.out.print(‘*’).
* 3. System.out.println can be used to move to the next line.
* 4. System.out.print(”) can be used to display a space for the last [...]

Chapter 5: Control Statements Part II (Exercise 5.13)

Posted by: Chyne on: October 11, 2008

/* Exercise 5.13
* 1. Modify the compound-interest application of Fig.5.6
* 2. Repeat the steps for interest rate of 5%, 6%, 7%, 8%, 9% and 10%.
* 3. Use a for loop to vary the interest rate.
*/
package Exercises;
public class CompoundInterest {
public static void main(String[] args) {
double amount; // amount on deposit at end of each year
double [...]

Chapter 5: Control Statements Part II (Exercise 5.12)

Posted by: Chyne on: October 11, 2008

/* Exercise 5.12
* 1. Evaluates the factorials of the integers from 1 to 5.
* 2. Display the results in tabular format.
*
*/
package Exercises;
import java.math.BigInteger;
public class Factorial {
public static void main(String[] args) {
// initialization phase
BigInteger n = BigInteger.ONE;
int i;
// loop until reaches 5
for (i = 1; i <= 5; i++) {
n = n.multiply(BigInteger.valueOf(i));
// display [...]


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).

 

October 2008
M T W T F S S
« Sep   Nov »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Archives


StatCounter

free hit counters