Could anyone give me a hand converting this Python script to Java?
This is the code
theHex = input("Hex: ").split()
theShift = int(input("Shift: "))
result = ""
for i in range (len(theHex)):
result += (hex((int(theHex[i],16) + theShift))).split('x')[1] + " "
print(result)
Here is what I've got
System.out.print("Please enter the hex: ");
String theHex = BIO.getString();
String[] theHexArray = theHex.split(" ");
System.out.print("Please enter the value to shift by: ");
int theShift = BIO.getInt();
String result[] = null;
for( int i = 0 ; i < theHex.length() ; i++ ){
//result += (hex((int(theHex[i],16) + theShift))).split('x')[1] + " "
}
toText(result[]);
BIO is a class I have to collect Strings and Ints. Think of it as basically a scanner.
Could anyone help me translate the last line?
EDIT Here is the toText method
public static void toText(String theHexArray[]){
String theHex = "";
for(int i = 0 ; i < theHexArray.length ; i++ ){
theHex += theHexArray[i];
}
StringBuilder output = new StringBuilder();
try{
for (int i = 0; i < theHex.length(); i+=2){
String str = theHex.substring(i, i+2);
output.append((char)Integer.parseInt(str, 16));
}
}catch(Exception e){
System.out.println("ERROR");
}
System.out.println(output);
}
java.util.Arrays.toString(result)