2
have to 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;
}
That’s one way I did it:
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 html and only print the code, it’s much easier, I don’t need to do the indentation code. But I think the code is very "dirty", so I decided to leave it separate in a javascript to print in html. there is a simpler way to indent?
Good evening, Did any of the answers solve your problem?
– Guilherme Nascimento