在Joptionpane中,我的角色在对话框消息中逐一显示。 我需要它们来形成一个单词,例如:如果我使用Sytem.out.println(c)它将在一行中显示它们。我想在joptionpane中一起显示它们
for (int i = 0; i < encrypt.length(); i++) {
char c = encrypt.charAt(i);
if (Character.isLetter(c)) {
c -= shift;
if(c < 'A'){
c = (char) (((int) c + (int) ('A')) % 26 + (int) ('A'));
}else{
c = (char) (((int) c - (int) ('A')) % 26 + (int) ('A'));
}
JOptionPane.showMessageDialog(null, c);
}
}
答案 0 :(得分:0)
String result = "";
for (int i = 0; i < encrypt.length(); i++) {
char c = encrypt.charAt(i);
if (Character.isLetter(c)) {
c -= shift;
if(c < 'A'){
c = (char) (((int) c + (int) ('A')) % 26 + (int) ('A'));
}else{
c = (char) (((int) c - (int) ('A')) % 26 + (int) ('A'));
}
}
result += String.valueOf(c);
}
JOptionPane.showMessageDialog(null, result);