0
Why this simple code gives outofmemory exception?
public class Program { public static void main(String[] args) { String [] arr={"if this simple string gives error?"}; int i=0; while(i<10) arr[0]+=arr[0]; System.out.println(arr[0]); } }
3 Answers
+ 11
It's an infinite loop. You have to increment i inside the loop.
+ 1
Because you have unlimited string concatenation, as far as I can see.
Your while loop never ends.
+ 1
Ha ha ha, what a pity of me. Such a foolish mistake. Thank you 'Ivan G' and 'Tashi N'.đ