0

Hi plzz! i need some help i dont feel well! anyone tell me how to s.o.p in a nonincreasing way an array please Here's the src👇

import java.util.Scanner; public class test { public static void main(String[] red) { int tab[]={1,2,3,4}; int tmp; for(int i=0;i<4;i++) { if(tab[i]<tab[i+1]) { tmp=tab[i]; tab[i]=tab[i+1]; tab[i+1]=tmp; } } for(int i=0;i<4;i++) { System.out.println(tab[i]); } } }

19th Jun 2019, 6:56 PM
Guibi Zart
Guibi Zart - avatar
10 Antworten
+ 11
Airree Sorry but you are wrong 😉 you can place any name in place of args In that code the problem was arise in line no 10 chek it out
19th Jun 2019, 7:19 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 10
I think you want in that array elements are placed in decrising order.
19th Jun 2019, 7:30 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 2
you have index 0 to 3 but you address 3 and 3+1 and it is out of index, here: if(tab[i]<tab[i+1]) do this for(int i=0; i<3; i++) { To sort the array in this way, 3 is not enough cycles to complete this array
19th Jun 2019, 7:45 PM
zemiak
+ 1
Yh! But u can change the args if u want it is not a problem.
19th Jun 2019, 7:06 PM
Guibi Zart
Guibi Zart - avatar
0
The problem is with this code, that it doesn't run the main method because you didn't write String[] args. Otherwise, I see no problems with your code
19th Jun 2019, 7:04 PM
Airree
Airree - avatar
0
Yes, but java takes only methods that are public static void main(String[] args) as an entry point; otherwise it is just a normal method
19th Jun 2019, 7:08 PM
Airree
Airree - avatar
0
No i think so to java the keyword is main
19th Jun 2019, 7:10 PM
Guibi Zart
Guibi Zart - avatar
0
Did u try to run it please?
19th Jun 2019, 7:10 PM
Guibi Zart
Guibi Zart - avatar
0
To follow conventions u can't change but if u do it is not a problem
19th Jun 2019, 7:26 PM
Guibi Zart
Guibi Zart - avatar
0
I know its in line 10 but im stucked
19th Jun 2019, 7:27 PM
Guibi Zart
Guibi Zart - avatar