My task:Write nested for loops to produce the following output with each line  48 characters wide:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~+~++~++~++~++~++~++~++~++~++~++~++~++~++~++~++~+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~This is my idea, but I guess it's pretty much redundant. If so, how can I minimize redundancy here? My output is correct, by the way.public class Exercises {    public static void main (String[] args){    for (int i = 1; i <= 4; i++){        for (int j = 1; j <= 12; j++){            System.out.print(~);        }    }            System.out.println();            System.out.print(~);    for (int i = 1; i <=15; i++){            System.out.print(+~~);    }            System.out.println(+~);            System.out.print(+~);    for (int i = 1; i <= 15; i++){            System.out.print(++~);        }            System.out.println(+);    for (int i = 1; i <= 4; i++){        for (int j = 1; j <= 12; j++){            System.out.print(~);        }    }  }}
Writing nested for loops to produce certain output
java;programming challenge;ascii art
for (int i = 1; i <= 4; i++){    for (int j = 1; j <= 12; j++){        System.out.print(~);    }}System.out.println();can easily be:for (int i = 0; i < 48; i++) {    System.out.print('~');}System.out.println();Some edits:Improved formatting: ){ to ) {Simplified to one for loop that runs from 0 to 47 (start at 0, run to less than 48)Print a single char instead of a String with one char in it to improve performanceThis:        System.out.print(~);for (int i = 1; i <=15; i++){        System.out.print(+~~);}        System.out.println(+~);Can be this:for (int i = 0; i < 16; i++){    System.out.print(~+~);}System.out.println();What changed:Better formattingLoops and prints the ~+~ pattern        System.out.print(+~);for (int i = 1; i <= 15; i++){        System.out.print(++~);    }        System.out.println(+);to:for (int i = 0; i < 16; i++){    System.out.print(+~+);}System.out.println();Changes made:Better formattingLoops and prints the +~+ patternAll of the fixes have some things in common:Indentation and formattingFind the correct patternOther changes:Use methods:Currently all your code is in the main method. Split it up.Final code:public class Exercises {    public static void main (String[] args){        printTildes();        printTPT_Pattern();        printPTP_Pattern();        printTildes();    }    private static void printTildes() {        for (int i = 0; i < 48; i++){            System.out.print(~);        }        System.out.println();    }    private static void printTPT_Pattern() {        for (int i = 0; i < 16; i++){            System.out.print(~+~);        }        System.out.println();    }    private static void printPTP_Pattern() {        for (int i = 0; i < 16; i++){            System.out.print(+~+);        }        System.out.println();    }}