//package com.nowjava;
/**
from
* 时 代 Java - nowjava.com
**/
public class Main {
public static void main(String[] argv) throws Exception {
double[] array = new double[] { 34.45, 35.45, 36.67, 37.78,
37.0000, 37.1234, 67.2344, 68.34534, 69.87700 };
float exponent = 2.45678f;
System.out.println(java.util.Arrays.toString(exponentiateAll(array,
exponent)));
}
/**
* Exponentiates all values in an array of doubles by a given exponent.
*
* @param array Array of doubles to be exponentiated.
* @param exponent An exponent.
* @return Array with exponentiated values.
*/
public static double[] exponentiateAll(double[] array, float exponent) {
for (int i = 0; i < array.length; i++) {
array[i] = Math.pow(array[i], exponent);
}
/**from 时 代 J a v a 公 众 号 - nowjava.com**/
return array;
}
/**
* Exponentiates all values in an array of integers by a given exponent.
*
* @param array Array of integers to be exponentiated.
* @param exponent An exponent.
* @return Array with exponentiated values.
*/
public static double[] exponentiateAll(int[] array, float exponent) {
double[] newArray = new double[array.length];
for (int i = 0; i < array.length; i++) {
newArray[i] = Math.pow(array[i], exponent);
}
return newArray;
}
/**
* Exponentiates all values in an array of floats by a given exponent.
*
* @param array Array of floats to be exponentiated.
* @param exponent An exponent.
* @return Array with exponentiated values.
*/
public static float[] exponentiateAll(float[] array, float exponent) {
float[] newArray = new float[array.length];
for (int i = 0; i < array.length; i++) {
newArray[i] = (float) Math.pow(array[i], exponent);
}
return newArray;
}
/**
* Exponentiates all values in an array of longs by a given exponent.
*
* @param array Array of longs to be exponentiated.
* @param exponent An exponent.
* @return Array with exponentiated values.
*/
public static double[] exponentiateAll(long[] array, float exponent) {
double[] newArray = new double[array.length];
for (int i = 0; i < array.length; i++) {
newArray[i] = Math.pow(array[i], exponent);
}
return newArray;
}
/**
* Exponentiates all values in an array of bytes by a given exponent.
*
* @param array Array of bytes to be exponentiated.
* @param exponent An exponent.
* @return Array with exponentiated values.
*/
public static float[] exponentiateAll(byte[] array, float exponent) {
float[] newArray = new float[array.length];
for (int i = 0; i < array.length; i++) {
newArray[i] = (float) Math.pow(array[i], exponent);
}
return newArray;
}
/**
* Exponentiates all values in a matrix of doubles by a given exponent.
*
* @param matrix Matrix of doubles to be exponentiated.
* @param exponent An exponent.
* @return Matrix with exponentiated values.
*/
public static double[][] exponentiateAll(double[][] matrix,
float exponent) {
for (double[] column : matrix) {
for (int j = 0; j < matrix[0].length; j++) {
column[j] = Math.pow(column[j], exponent);
}
}
return matrix;
}
/**
* Exponentiates all values in a matrix of integers by a given exponent.
*
* @param matrix Matrix of integers to be exponentiated.
* @param exponent An exponent.
* @return Matrix with exponentiated values.
*/
public static double[][] exponentiateAll(int[][] matrix, float exponent) {
double[][] newMatrix = new double[matrix.length][matrix[0].length];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
newMatrix[i][j] = Math.pow(matrix[i][j], exponent);
}
}
return newMatrix;
}
/**
* Exponentiates all values in a matrix of floats by a given exponent.
*
* @param matrix Matrix of floats to be exponentiated.
* @param exponent An exponent.
* @return Matrix with exponentiated values.
*/
public static float[][] exponentiateAll(float[][] matrix, float exponent) {
float[][] newMatrix = new float[matrix.length][matrix[0].length];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
newMatrix[i][j] = (float) Math.pow(matrix[i][j], exponent);
}
}
return newMatrix;
}
/**
* Exponentiates all values in a matrix of longs by a given exponent.
*
* @param matrix Matrix of longs to be exponentiated.
* @param exponent An exponent.
* @return Matrix with exponentiated values.
*/
public static double[][] exponentiateAll(long[][] matrix, float exponent) {
/**代码未完, 请加载全部代码(NowJava.com).**/