-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindingPasssword.java
More file actions
65 lines (52 loc) · 1.6 KB
/
Copy pathFindingPasssword.java
File metadata and controls
65 lines (52 loc) · 1.6 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String fn = sc.next();
String ln = sc.next();
int pin = sc.nextInt();
int n = sc.nextInt();
int fLength = fn.length();
int lLength = ln.length();
String longName = "",smallName="";
if(fLength>lLength){
longName=fn;
smallName=ln;
}
else{
longName=ln;
smallName=fn;
}
String userId="";
userId = smallName.charAt(smallName.length()-1)+longName;
// left to right.
String newPin = String.valueOf(pin);
for(int i=0;i<newPin.length();i++){
if(i==n-1){
userId+=newPin.charAt(i);
}
}
// right to left
for(int i=newPin.length()-1;i>=0;i--){
if(i==newPin.length()-n){
userId+=newPin.charAt(i);
}
}
// toggle code.
String res="";
for(int i=0;i<userId.length();i++){
if(userId.charAt(i)>='a' && userId.charAt(i)<='z'){
int x = userId.charAt(i)-32;
res+=(char)x;
}
else if(userId.charAt(i)>='A' && userId.charAt(i)<='Z'){
int x = userId.charAt(i)+32;
res+=(char)x;
}
else{
res+=userId.charAt(i);
}
}
System.out.println(res);
}
}