Skip to content

Commit e35817e

Browse files
authored
Merge pull request ronijpandey#18 from atabunnu/master
Commented DigitalMax.java
2 parents abeb2a0 + 99c8653 commit e35817e

1 file changed

Lines changed: 41 additions & 26 deletions

File tree

DigitalMax.java

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,49 @@
33
import java.util.*;
44

55
public class DigitalMax {
6-
7-
public static void main(String[] agrs) {
8-
Scanner in = new Scanner(System.in);
6+
7+
public static void main(String[] agrs)
8+
{
9+
Scanner in =new Scanner(System.in);
10+
911
//User will enter a number
1012
System.out.println("Enter a number :");
11-
12-
int n = in.nextInt();
13-
14-
int temp = 0, a;
15-
16-
int[] arr = {8, 9, 8, 9, 9, 9, 8, 9, 8, 9};
17-
18-
while (n > 0) {
19-
a = n % 10;
20-
21-
temp = temp * 10 + arr[a];
22-
23-
n = n / 10;
13+
14+
int n=in.nextInt();
15+
16+
//set 'temp', 'a' counter to 0
17+
int temp=0,a;
18+
19+
//initializing the array
20+
int[] arr={8,9,8,9,9,9,8,9,8,9};
21+
22+
//if user enters a positive figure
23+
while(n>0)
24+
25+
{
26+
//remainder of 'a'
27+
a=n%10;
28+
29+
//get array value accordingly of it's index
30+
temp=temp*10+arr[a];
31+
32+
n=n/10;
2433
}
25-
int ans = 0;
26-
27-
while (temp > 0) {
28-
a = temp % 10;
29-
30-
ans = ans * 10 + a;
31-
32-
temp = temp / 10;
34+
35+
//declaring answer variable
36+
int ans=0;
37+
38+
while(temp>0)
39+
{
40+
//calculating remainder of a
41+
a=temp%10;
42+
43+
//calculating answer
44+
ans=ans*10+a;
45+
46+
temp=temp/10;
3347
}
34-
System.out.println("Maximum no:" + " " + ans);
48+
//answer prompt
49+
System.out.println("Maximum no:"+" "+ans);
3550
}
36-
}
51+
}

0 commit comments

Comments
 (0)