-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchewacca.java
More file actions
55 lines (43 loc) · 760 Bytes
/
chewacca.java
File metadata and controls
55 lines (43 loc) · 760 Bytes
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
52
package assignment;
import java.util.Scanner;
public class chewbacca {
public static void main(String[] args) {
Scanner scn =new Scanner(System.in);
long num=scn.nextLong();
long num1=0,rem=0,ans=0,t=0,c=0,f=1,num2=num,s=0,v=0 ;
while(num2!=0)
{
num2=num2/10 ;
s++ ;
}
while(num!=0)
{
rem=num%10 ;
if(rem>=5)
{
rem=9-rem;
}
if(rem==0&&f==1&&v!=s-1)
{
c++ ;
}
if(v==s-1&&rem==0)
{
rem=num%10 ;
}
if(rem!=0)
{f=0; }
num1=num1*10+rem ;
num=num/10 ;
v++;
}
while(num1!=0)
{
rem=num1%10 ;
if(t==1||rem!=0)
{ans=ans*10+rem ;t=1; }
num1=num1/10 ;
}
System.out.println(ans*(int)Math.pow(10,c));
}
}