+ 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
18 Answers
+ 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);
+ 16
Simon Nikiforov Thanks a lot bro ๐๐
Glad to like my comment and my code ๐๐
+ 12
one-liner in js
console.log(prompt("Please enter a number.").toString().split("").reverse().join(""));
+ 10
p gets.chomp.reverse.to_i
ยฏ\_(ใ)_/ยฏ
+ 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
+ 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
+ 2
https://code.sololearn.com/cTG58Hdqid3f/#py