Skip to content

Instantly share code, notes, and snippets.

@bragboy
Created November 12, 2015 11:10
Show Gist options
  • Select an option

  • Save bragboy/351f876d8714773adfbe to your computer and use it in GitHub Desktop.

Select an option

Save bragboy/351f876d8714773adfbe to your computer and use it in GitHub Desktop.
package misc.integers;
public class RevNum {
public static void main(String args[]){
int sampleNum = 12345678;
System.out.println("Input Num : "+sampleNum);
int reversedNum = 0;
while(sampleNum!=0){
reversedNum = reversedNum*10 + sampleNum%10;
sampleNum = sampleNum/10;
}
System.out.println("Reversed Num : "+reversedNum);
}
}
//SAMPLE OUTPUT
//Input Num : 12345678
//Reversed Num : 87654321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment