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 [...]
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 [...]
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 [...]
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 [...]
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 [...]