Skip to content

Commit

Permalink
Reverse a number if it is odd
Browse files Browse the repository at this point in the history
  • Loading branch information
Arijit-SE committed Mar 14, 2023
1 parent a2e7faf commit 535d64d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Odd_Reverse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Take a number. If it odd then reverse it, otherwise print "Can not reverse"
*
* Input : 123
* Output : 321
*
* Input : 234
* Output : Can not reverse
*/

import java.util.*;
public class Odd_Reverse
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
if(num%2==0)
{
System.out.println("Can't reverse");
}
else
{
int sum=0;
while(num>0)
{
int rem = num%10;
sum = sum*10 + rem;
num = num/10;
}
System.out.println("The reverse of the number : "+sum);
}
}
}

0 comments on commit 535d64d

Please sign in to comment.