我得到一道题目,要求输入4个英文字母,左右一个简单的string,然后将他变换成char,再改为int,然后将之平方,再变成char。 比如输入“abcd”,运行后就会得到“kjih”。我尝试自己写了java,但只写到一半
import javax.swing.JOptionPane;
public class Assignment2 {
public static void main(String[] args) {
String word =
JOptionPane.showInputDialog("Enter your four-letter word: ");
char[] code = word.toCharArray();int code2 = (int)code; \\问题就是这里System.out.print(code2);
}
}说这个是不可转换的类型,这个应该怎样解决?以防我理解错误,原题在这~~
Write a Java program that encrypts a four-letter word. The word should be entered by the
user as a single string using the JOptionPane class. Each letter in the word should be
replaced by the Unicode character that is seven characters after it, and then the sequence of
letters should be reversed. The encrypted word should then be displayed in the terminal
window. For example, the string “abcd” is encoded as “kjih” and the string “java” is encoded as
“h}hq”.
import javax.swing.JOptionPane;
public class Assignment2 {
public static void main(String[] args) {
String word =
JOptionPane.showInputDialog("Enter your four-letter word: ");
char[] code = word.toCharArray();int code2 = (int)code; \\问题就是这里System.out.print(code2);
}
}说这个是不可转换的类型,这个应该怎样解决?以防我理解错误,原题在这~~
Write a Java program that encrypts a four-letter word. The word should be entered by the
user as a single string using the JOptionPane class. Each letter in the word should be
replaced by the Unicode character that is seven characters after it, and then the sequence of
letters should be reversed. The encrypted word should then be displayed in the terminal
window. For example, the string “abcd” is encoded as “kjih” and the string “java” is encoded as
“h}hq”.
比如:
char ch[] = {'a','b','c'};
int[] arr = new arr[ch.length];
for(int i = 0; i< ch.length; i++){
arr[ i ] = Integer.parsetInt(String.valueOf(ch[i]));
}
replaced by the Unicode character that is seven characters after it
条件和你给的数也不符合啊,而且每有分,不做了(这个java api中没有转换的,找半天也没找到)
这次当是给新手的免费解答吧, public static void main(String args[]) {
char[] code2;
char a;
String word =
JOptionPane.showInputDialog("Enter your four-letter word: ");
code2=word.toCharArray() ;
for(int i:code2)
{i+=7;
System.out.println((char)i);
}
}