Why is the code not giving exected result?
please find the cause
Code not giving expected result
@kavit i) First of all you dont need to use these useless lines like :
System.out.println(“Enter the number of elements in an array”);
System.out.println(“Please enter the “+n+” numbers in form of 0,1,2”);
ii) Second : you need to print every element in new line not in the same line so use println instead of print
iii) MAJOR MISTAKE THAT YOU HAVE DONE IS IN SWAP FUNCTION YOU HAVE ASSIGNED PARAMETERS i and j for indexes but when you call swap function you have passed element of array instead of index.
iv) Another major mistake is you have to use else if statement not if if bcoz it can cause multiple conditions to be true in single iteration.
CORRECTED CODE is in the below link :
Now it worked…Thanks a lot Piyush
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.