function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nishant Kumar 274Nishant Kumar 274 

Write a program in apex that prompts the user to input an integer and then outputs the number with the digits reversed. For example, if the input is 12345, the output should be 54321.

Best Answer chosen by Nishant Kumar 274
CharuDuttCharuDutt
Hii Nishant
Try Below Code
string str = '0123456789';
string revStr = str.reverse();
system.debug(revStr);


#################################################################


String forward = '0123456789';
String reverse = '';

for (Integer i = forward.length()-1; i >= 0; i--)
{
	reverse += forward.substring(i, i+1);
}

system.debug(reverse);
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Nishant
Try Below Code
string str = '0123456789';
string revStr = str.reverse();
system.debug(revStr);


#################################################################


String forward = '0123456789';
String reverse = '';

for (Integer i = forward.length()-1; i >= 0; i--)
{
	reverse += forward.substring(i, i+1);
}

system.debug(reverse);
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer
Nishant Kumar 274Nishant Kumar 274
Thanks a lot Charu.