I want to print an 2 dimensional double Array to the console.
public class arrayprinter {
public static void main(String[] args) {
double[][] multi = new double[][]{
{ 10, 20, 30, 40, 50},
{ 1.1, 2.2, 3.3, 4.4},
{ 1.2, 3.2},
{ 1, 2, 3, 4, 5, 6, 7, 8, 9}
};
print(multi);
}
private static void print(double[][] e){
for(int i=0; i>e.length;i++) {
print(e[i]);
}
}
public static void print(double[] e) {
for(int i=0; i>e.length;i++) {
System.out.print(e[i]); }
}
}
When i click the play button in eclipse there is only: <terminated>...
and no printed array in the console. Can someone say me what I am doing wrong?
Your program never reaches the line which prints. You start at i=0
and increment it while it's bigger that e.length
, but it never is, because the loop exists at the first run (i = 0
and 0
is not bigger than e.length
so it exists the loop)
use these:
private static void print(double[][] e) {
for (int i = 0; i < e.length; i++) {
print(e[i]);
}
}
public static void print(double[] e) {
for (int i = 0; i < e.length; i++) {
System.out.print(e[i]);
}
}
I replaced the >
with <
in the loop.