+ 5

Hello everyone i made this code but i want to add something to it

The thing is i know what to do but i dont know how to do it😭 */num i mean the numbers you put in the array */ Okay i want if (num >= 0){ System.out.printIn (reaults the code i made)} Else (num <0 ){ Syso(cant write num less than0) } Also i want to add the 2 bigger numbers in the array . know i wrote the biggest number and it works .i will try writing for seconed bigger number https://code.sololearn.com/cIzv9qzQBX9u/?ref=app

3rd Dec 2018, 7:28 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
2 Answers
+ 14
● For making code work for +ve numbers & showing -ve numbers if less than 0, for that U can use of if() else conditions inside loop: //here is rough code : if(nums[i]>0) System.out.println(nums[i]); else System.out.println("-ve"); ● For taking biggest & 2nd biggest number out of array : best way is to sort array using "Arrays.sort(nums);" & after it take element at index (l-1) & (l-2) as biggest & 2nd biggest number number. //alternatively, U can solve it using loops & replacing elemnts from 1 index to other[might U successfully done that in edited code]👍
3rd Dec 2018, 7:44 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
Thanks i made secound max now i will add it and will try add if thanks for the help
3rd Dec 2018, 7:48 AM
Dareen Moughrabi
Dareen Moughrabi - avatar