We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4f79d99 commit 854deb3Copy full SHA for 854deb3
βMiscellaneous/ReplaceAll0with5InInputInteger.javaβ
@@ -0,0 +1,29 @@
1
+/**
2
+ * Given a integer as a input and replace all the β0β with β5β in the integer.
3
+ * Use of array to store all digits is not allowed.
4
+ */
5
+
6
+class ReplaceAll0with5InInputInteger {
7
8
+ public static int recursivelyReplaceDigits(int num){
9
10
+ if(num == 0)
11
+ return 0;
12
+ int digit = num %10;
13
+ if(digit == 0)
14
+ digit = 5;
15
+ return recursivelyReplaceDigits(num/10)*10+digit;
16
+ }
17
18
+ public static int replaceDigits(int num){
19
+ if(num==0)
20
+ return 5;
21
+ return recursivelyReplaceDigits(num);
22
23
24
+ public static void main(String [] args){
25
+ System.out.println(replaceDigits(1230450));
26
+ System.out.println(replaceDigits(0));
27
+ System.out.println(replaceDigits(50));
28
29
+}
0 commit comments