Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,011 questions

51,958 answers

573 users

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 90 views
1 answer 86 views
1 answer 73 views
1 answer 74 views
1 answer 80 views
1 answer 82 views
...