forked from ronijpandey/Java-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigitalMax.java
51 lines (36 loc) · 1.12 KB
/
DigitalMax.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package javacodes;
import java.util.*;
public class DigitalMax {
public static void main(String[] agrs)
{
Scanner in =new Scanner(System.in);
//User will enter a number
System.out.println("Enter a number :");
int n=in.nextInt();
//set 'temp', 'a' counter to 0
int temp=0,a;
//initializing the array
int[] arr={8,9,8,9,9,9,8,9,8,9};
//if user enters a positive figure
while(n>0)
{
//remainder of 'a'
a=n%10;
//get array value accordingly of it's index
temp=temp*10+arr[a];
n=n/10;
}
//declaring answer variable
int ans=0;
while(temp>0)
{
//calculating remainder of a
a=temp%10;
//calculating answer
ans=ans*10+a;
temp=temp/10;
}
//answer prompt
System.out.println("Maximum no:"+" "+ans);
}
}