+ 1

Friends i want to print digits in reverse order. Like 12345 to 54321. Please tell me what's wrong in code.

class reverse{ public static void main(String[] args){ int digits[] = {1,2,3,4,5}; int i = digits.length; while(i>0){ System.out.println(digits[i-1]); --i;} }}

27th Dec 2017, 6:52 AM
Sahil
Sahil - avatar
16 Answers
27th Dec 2017, 7:02 AM
Scooby
Scooby - avatar
+ 6
Change : i < 0 By : i > 0
27th Dec 2017, 6:56 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
If you want : 54321 Instead of : 5 4 3 2 1 Change : println By : print
27th Dec 2017, 7:04 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
thanks my friend for help
27th Dec 2017, 7:04 AM
Sahil
Sahil - avatar
+ 2
the above code is not working
27th Dec 2017, 7:02 AM
Sahil
Sahil - avatar
+ 2
ok
27th Dec 2017, 7:04 AM
Sahil
Sahil - avatar
+ 2
Java != JS
27th Dec 2017, 5:48 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
@Sahil, do not listen to @Talluri, his answer is the exact same code you post at the beginning, which obviously did not work
27th Dec 2017, 10:15 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
/* for php this the code you need but if you are trying what iam thinking about..its not gonna work but its always good to practice and try */ $amount = str_replace("0.0001", "9.999", " 0.0001");
27th Dec 2017, 12:04 PM
iTech
iTech - avatar
+ 1
@UNlimitedLearN, he wants java help, not JS or php ^^
27th Dec 2017, 12:09 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
i tried it with php str_replace but its not working....if you are trying what iam trying too :-) but keep trying anyway,persistence is the engine of knowledge
27th Dec 2017, 7:29 AM
iTech
iTech - avatar
0
class reverse{ public static void main(String[] args){ int digits[] = {1,2,3,4,5}; int i = digits.length; while(i<0){ System.out.println(digits[i-1]); --i;} }} //try this
27th Dec 2017, 9:31 AM
Talluri Saisumanth
Talluri Saisumanth - avatar
0
it show "no output" always
27th Dec 2017, 10:08 AM
Sahil
Sahil - avatar
0
/** simple reverse code bro enjoy **/ var amount = ['1', '2', '3', '4', '5']; var reversed = amount.reverse(); console.log(reversed);
27th Dec 2017, 11:22 AM
iTech
iTech - avatar
0
/** this best code you can do but dont know why on sololearn simulator it tells illegal return **/ function reverseString(str) { var splitString = "0.001".split(""); var reverseArray = ["0.", "0", "0", "1"].reverse(); var joinArray = ["1.", "0", "0", "0"].join(""); } return joinArray;
27th Dec 2017, 11:56 AM
iTech
iTech - avatar
0
whatever you said bro,i hate java js jquery anything related to java i hate it lol iam php & pyhon jeek,i thought he's searching reversing dicegames like bitsler,are you trying too?
27th Dec 2017, 5:38 PM
iTech
iTech - avatar