From 535d64db69f1e5a57407b344d28dddce2c186363 Mon Sep 17 00:00:00 2001 From: ARIJIT GHOSH Date: Tue, 14 Mar 2023 08:44:30 +0530 Subject: [PATCH] Reverse a number if it is odd --- Odd_Reverse.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Odd_Reverse.java diff --git a/Odd_Reverse.java b/Odd_Reverse.java new file mode 100644 index 0000000..32b9364 --- /dev/null +++ b/Odd_Reverse.java @@ -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); + } + } + } \ No newline at end of file