任何人都可以给我一个手把这个Python脚本转换为Java吗?Python到Java代码转换
这是代码
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)
这里是我有
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是一类我有收集字符串和整数的。把它看作基本上是一台扫描仪。
任何人都可以帮我翻译最后一行吗?
编辑 这里是toText方法
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)' – PeterMmm
@JeroenVannevel我只是为了简单而使用它,因为这是我已经习惯了。至于评论,我试过。然而,由于我对python不熟悉,我一直无法找到它在做什么。我看过文档,但没有找到它。如果你可以用面向Java的方式解释它,这可能会有所帮助。 – Kyle93