Lab3 Solution
public class StringMagic {
public String removeSpace(String s) {
int pos_space = s.indexOf(" ");
return s.substring(0, pos_space) + s.substring(pos_space+1);
}
public String replaceSpace(String s) {
return s.replaceAll(" ", "...");
}
public String cipher(String s, int t) {
int t0 = (int)('a');
int t1 = (int)s.charAt(0)-t0;
int t2 = (int)s.charAt(1)-t0;
int t3 = (int)s.charAt(2)-t0;
System.out.println(t1);
int g1 = (t1+t)%26;
int g2 = (t2+t)%26;
int g3 = (t3+t)%26;
int c1 = t0+g1;
int c2 = t0+g2;
int c3 = t0+g3;
return "" + (char)c1 + (char)c2 + (char)c3;
}
}
Last updated