Reverse an Integer -LeetCode

import java.util.ArrayList;
import java.util.List;

import org.testng.annotations.Test;

/**
* @author asharda
*
*/
public class TestReverseInteger {

@Test
public void testReverseInteger()
{
int num=123;
int div=num;
int rem=0;
List<Integer> list=new ArrayList<Integer>();
while(div>100)
{
div=num/10;
rem=num%10;
list.add(rem);

}
list.add(div%10);
list.add(div/10);
Integer [] arr=list.stream().toArray(Integer[]::new);
System.out.print(“Reversed Integer is “);
for (int val:arr)
{
System.out.print(val);
}

}
}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Java, LeetCode Solutions, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s