-1

I have the following code

public class Test {

public static void main(String[] args) {

    int []n= new int[6000];

    for(int i=0;i<6000;i++){
        n[i]=1;
    }

    for(int i=0;i<6000;i++){
        System.out.print(n[i]);
    }



}

There is no output in the console. However if I decrease the limit for the loop like ,

  for(int i=0;i<3000;i++){
        System.out.print(n[i]);
    }

Now I can see the output. It looks like System.out.print() only prints if all the numbers fit in a single line.

Now how can I print all the numbers which fit in a single line and later go to the next line and print rest of them?

Kas1
  • 145
  • 1
  • 4
  • 14

1 Answers1

0

To answer your question "how can I print all the numbers which fit in a single line and later go to the next line" :
Simply start a new row after every lineLength prints:

    public static void main(String[] args) {

        int[]n= new int[6000];
        Arrays.fill(n, 1);

        int lineLength = 80;
        int timesPrinted = 0;

        for (int element : n) {

            System.out.print(element);

            if(timesPrinted == lineLength) {
                System.out.print("\n");
                timesPrinted = 0;
            }else {
                timesPrinted++;
            }
        }

    }
c0der
  • 18,467
  • 6
  • 33
  • 65