[CHALLENGE] Flipping numbers | SoloLearn: Learn to code for FREE!

+17

[CHALLENGE] Flipping numbers

Flipping numbers flip your number backwards. For example: Input: 1836 Output: 6381 Input: 15788 Output: 88751 Write the program that flips the entered number. My version https://code.sololearn.com/cXig2it0O4WJ/?ref=app

4/25/2018 7:57:00 PM

Shimon

20 Answers

New Answer

+18

https://code.sololearn.com/cAlwT7YkyqQt/?ref=app https://code.sololearn.com/cfLCd2I3wGJY/?ref=app The second one is Oneliner

+24

public class FlippingNumber{ public static void main(String args[]){ int a=3564; String b=Integer.toString(a); StringBuffer obj=new StringBuffer(b); obj.reverse(); String c=obj.toString(); int d=Integer.parseInt(c); System.out.println(d);

+18

https://code.sololearn.com/cB9UsPyh8K23/?ref=app

+16

Simon Nikiforov Thanks a lot bro 💙😉 Glad to like my comment and my code 💚💕

+13

https://code.sololearn.com/cy26M72V2D2g/?ref=app

+12

one-liner in js console.log(prompt("Please enter a number.").toString().split("").reverse().join(""));

+11

#Python https://code.sololearn.com/co5K5HPD69cU/?ref=app

+10

p gets.chomp.reverse.to_i ¯\_(ツ)_/¯

+9

https://code.sololearn.com/cI2Bbuhxvq7z/?ref=app

+9

https://code.sololearn.com/c8CGjgKVAAN9/?ref=app

+8

With a Ruby oneliner 😉👍 https://code.sololearn.com/c3HbTJrt78hM/?ref=app https://code.sololearn.com/c53k2BTV2o9x/?ref=app https://code.sololearn.com/cmTI1RzE7n1o/?ref=app https://code.sololearn.com/ctdyEILJmOYq/?ref=app https://code.sololearn.com/W5twGmh0scL2/?ref=app https://code.sololearn.com/cIky9L02ysrw/?ref=app https://code.sololearn.com/c9WNyv8YmPYL/?ref=app

+7

Solutions in C++: 1) int n; cin>>n; while (n) { cout<<n % 10; n /= 10 } 2) string s; cin>>s; for (int i = s.length() - 1; i >= 0; i—) cout<<s[i];

+7

number=1234 number+=""; number=number.split("").reverse().join(""); number=parseInt(number) alert(number) //4321

+7

It's called reversing, not flipping. You convert the number to a string then reverse the string, and optionally convert the reversed string back to a number depending on what you want to do with it. https://code.sololearn.com/c9GjmJ8C24mL/?ref=app

+6

To flip a number - not a string as others do : https://code.sololearn.com/cUZMG2p7jSR9/?ref=app

+6

int reverse(int num) { int remainder = 0, rev = 0; while (num != 0) { remainder = num % 10; rev = rev * 10 + remainder; num = num / 10; } return rev; }

+5

Eazy oneliner https://code.sololearn.com/c2W7D8l9Ne1a/?ref=app

+4

https://code.sololearn.com/cXai64JhU2fR/?ref=app

+3

https://code.sololearn.com/c0TJRxoY3lks/?ref=app

+2

https://code.sololearn.com/cTG58Hdqid3f/#py