How can you print this in an easier way?
public static void swap(int[] list, int i, int j) {
/* This method simply takes an array
and swaps its values at index i and j */
int temp = list[i];
list[i] = list[j];
list[j] = temp;
}
This was a way I did:
HTML
<div class="modal-body">
<span id="codigoJava"></span>
</div>
Javascript
var string =
'<textarea wrap="off" readonly style="width:100%; height:400px; overflow:scroll; font-family:Arial; font-size:8pt;">'+"\n"+
"\t"+"public static void swap(int[] list, int i, int j) {"+"\n"+
"\t"+"\t"+"int temp = list[i];"+"\n"+
"\t"+"\t"+"list[i] = list[j];"+"\n"+
"\t"+"\t"+"list[j] = temp;"+"\n"+
"\t"+"}"+"\n"+
'</textarea>'
;
document.getElementById('codigoJava').innerHTML = string;
If I create a textarea directly in the html and only printable the code, it is much easier, I do not need to do the indentation code. But I think the code gets very "dirty", so I decided to leave it separate in a javascript to start with in html. is there a simpler way to indent?