Register on the forum now to remove ALL ads + popups + get access to tons of hidden content for members only!

Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 08-01-2017, 03:00 AM   #1
sonakshibhathi
Registered User
 
Join Date: Jul 2017
Posts: 15
How to reverse an integer in Java?

Hi friends,
How to reverse an integer in Java?
please suggest to know..
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
sonakshibhathi is offline   Reply With Quote

Old 08-02-2017, 04:53 AM   #2
jackkodell12
Registered User
 
Join Date: Aug 2013
Posts: 98
Modding (%) the input int by 10 will extract off the rightmost digit. example: (1234 % 10) = 4.
Multiplying an integer by 10 will "push it left" exposing a zero to the right of that number, example: (5 * 10) = 50.
Dividing an integer by 10 will remove the rightmost digit. (
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jackkodell12 is offline   Reply With Quote
Old 08-29-2017, 01:50 AM   #3
ketul
Registered User
 
Join Date: Aug 2014
Location: Bangalore
Posts: 2,499
You can use below code for it.
public static void reverse(int n)
{
int temp = 0;
int count = 0;

while(n != 0)
{
if(n%10 == 0)count++;
temp = temp*10 + n %10;
n /= 10;
}
for(int i = 0; i < count; i++)
{
System.out.print(0);
}
System.out.println(temp);
}
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
ketul is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Jobs In Pune: A Career and Growth Perspective arshi1586 Java 1 01-19-2017 02:59 PM
How many kinds of enterprise beans do Java has? chinmay.sahoo Java 1 02-26-2016 09:45 PM
Have you ever wondered what is inside a java class file? cianfie Java 6 01-28-2015 10:09 PM
Do you know about Reverse SEO? christyronaldo1 General Discussion 7 12-23-2013 04:14 AM
The conclusion provided by the Black Hat Java Script andrebreton2121 Search Engine Optimization 6 10-17-2012 11:06 PM


All times are GMT -7. The time now is 06:50 AM.


Powered by vBulletin Copyright © 2013 vBulletin Solutions, Inc.