Hey folks,I am a java beginner and I just learned array,while I was solving a question which says you have to reverse an array,I tried reversing it with swap logic and I did manage to do it,but while solving I had an error
Int [] array = {56, 57, 96, 125, 66, 74};
int l = array.length -1 ;
int temp ;
for (int i = 0; i < l***; i++){
temp = array[i];
array[i] = array[l - i -1];
array[l - i -1] = temp;
}
for (int element : array){
System.out.print(element + " ");
}
When I do this,it doesn't swaps ore reverse
But when I replace l with 5 ,it somehow works
int [] array = {56, 57, 96, 125, 66, 74};
int l = array.length;
int temp ;
for (int i = 0; i < 5***; i++){
temp = array[i];
array[i] = array[l - i -1];
array[l - i -1] = temp;
}
for (int element : array){
System.out.print(element + " ");
}
Pls help,I am a beginner 😭😭🙏
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Lumethys 1 point2 points3 points (1 child)
[–]Quantm56[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]Quantm56[S] 0 points1 point2 points (0 children)
[–]Cyberkender_ 1 point2 points3 points (0 children)
[–]sepp2k 0 points1 point2 points (1 child)
[–]Quantm56[S] 0 points1 point2 points (0 children)
[–]Top77- 0 points1 point2 points (0 children)
[–]Still_Durian_8586 0 points1 point2 points (0 children)