|
-
Confused with decimal
Hi all,
I am running this program, it compile and run.
What I am getting is not what I want.
I want it to print only 2 decimal points.
How can I make print only two dec. instead of 15.
Thank you in advance.
public class array{
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);
}
} //
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks