Think in java 答案_Chapter 4_Exercise 19
来源:互联网 发布:网络写作平台 编辑:程序博客网 时间:2024/05/21 06:45
阅前声明: http://blog.csdn.net/heimaoxiaozi/archive/2007/01/19/1487884.aspx
/****************** Exercise 19 *****************
* Write a method that creates and initializes a
* two-dimensional array of double. The size of
* the array is determined by the arguments of
* the method, and the initialization values are
* a range determined by beginning and ending
* values that are also arguments of the method.
* Create a second method that will print the
* array generated by the first method. In main()
* test the methods by creating and printing
* several different sizes of arrays.
***********************************************/
public class E19_TwoDDoubleArray {
public static double[][] twoDDoubleArray(
int xLen, int yLen,
double valStart, double valEnd){
double[][] array = new double[xLen][yLen];
double increment =
(valEnd - valStart)/(xLen * yLen);
double val = valStart;
for(int i = 0; i < array.length; i++)
for(int j = 0; j < array[i].length; j++) {
array[i][j] = val;
val += increment;
}
return array;
}
public static void printArray(double[][] array){
for(int i = 0; i < array.length; i++) {
for(int j = 0; j < array[i].length; j++)
System.out.print(" " + array[i][j]);
System.out.println();
}
}
public static void main(String args[]) {
double[][] twoD =
twoDDoubleArray(4, 6, 47.0, 99.0);
printArray(twoD);
System.out.println("**********************");
double[][] twoD2 =
twoDDoubleArray(2, 2, 47.0, 99.0);
printArray(twoD2);
System.out.println("**********************");
double[][] twoD3 =
twoDDoubleArray(9, 5, 47.0, 99.0);
printArray(twoD3);
}
}
//+M java E19_TwoDDoubleArray
**The step value for the initialization range is calculated by dividing the range by the number of elements in the array.
- Think in java 答案_Chapter 4_Exercise 19
- Think in java 答案_Chapter 4_Exercise 4
- Think in java 答案_Chapter 2_Exercise 4
- Think in java 答案_Chapter 3_Exercise 4
- Think in java 答案_Chapter 4_Exercise 1
- Think in java 答案_Chapter 4_Exercise 2
- Think in java 答案_Chapter 4_Exercise 3
- Think in java 答案_Chapter 4_Exercise 5
- Think in java 答案_Chapter 4_Exercise 6
- Think in java 答案_Chapter 4_Exercise 7
- Think in java 答案_Chapter 4_Exercise 8
- Think in java 答案_Chapter 4_Exercise 9
- Think in java 答案_Chapter 4_Exercise 10
- Think in java 答案_Chapter 4_Exercise 11
- Think in java 答案_Chapter 4_Exercise 12
- Think in java 答案_Chapter 4_Exercise 13
- Think in java 答案_Chapter 4_Exercise 14
- Think in java 答案_Chapter 4_Exercise 15
- 字符串连接(string语句 )
- 字符串分解语句(unstring语句 )
- 检测语句(INSPECT)
- 条件的分类
- 一个小钩子程序
- Think in java 答案_Chapter 4_Exercise 19
- 分支语句
- 循环语句
- 出口语句(EXIT)
- 表的建立
- 可变长度的表
- http://www.zrit.com/rising/
- 给表赋初值
- 引用表元素