fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String A = "011010";
  13. System.out.println("Valor A: " +A);
  14. String resultado = invertir(A);
  15. System.out.println("Valor A invertido: " + resultado);
  16. }
  17.  
  18. public static String invertir (String valorInicial){
  19. String resultado ="";
  20. byte[] bytes = valorInicial.getBytes();
  21. for(byte b: bytes){
  22. b = (byte) (b ^ 1); //*OperaciĆ³n XOR
  23. String res = new String(new byte[] {b}); //*Convierte byte a String
  24. resultado += String.valueOf(res); //*Agrega valor a cadena resultante.
  25. }
  26. return resultado;
  27. }
  28.  
  29. }
Success #stdin #stdout 0.07s 27596KB
stdin
Standard input is empty
stdout
Valor A: 011010
Valor A invertido: 100101