How to get the reciprocal of the letters in a string with Java

1 Answer

0 votes
public class MyClass {
    static String get_reciprocal(String s) { 
        String tmp = "";
         
        for (int i = 0; i < s.length(); i++) { 
            if (Character.isUpperCase(s.charAt(i))) { 
                tmp += (char)('Z' - s.charAt(i) + 'A');
            } 
            else if (Character.isLowerCase(s.charAt(i))) { 
                    tmp += (char)('z' - s.charAt(i) + 'a');
                } 
                else { 
                    tmp += s.charAt(i); 
            } 
        } 
        return tmp;
    }
    public static void main(String args[]) {
        String s = "abc++def"; 
      
        s = get_reciprocal(s); 

        System.out.println(s);
    }
}



/*
run:

zyx++wvu

*/

 



answered Jan 17, 2020 by avibootz

Related questions

1 answer 120 views
1 answer 105 views
1 answer 96 views
1 answer 107 views
1 answer 98 views
1 answer 107 views
...