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]); } } }
10 odpowiedzi
+ 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
+ 10
I think you want in that array elements are placed in decrising order.
+ 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
+ 1
Yh! But u can change the args if u want it is not a problem.
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
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
0
No i think so to java the keyword is main
0
Did u try to run it please?
0
To follow conventions u can't change but if u do it is not a problem
0
I know its in line 10 but im stucked