
本帖最后由 木月火石 于 2013-4-21 00:07 编辑
(╯‵□′)╯︵┻━┻改进之后又找不到问题了,总感觉我在自娱自乐。。。。
跪求改了之后能循环
public class encode2013
{
public static void main(String[] args)
{
final String BLANK_STRING="";
final int ALPHABET_LENGTH=26;
final char FIRST_LETTER='A';
final char LAST_LETTER='Z';
String another = "y";
String delimited;
String inString;
String outString;
char currentLetter;
char outLetter;
int offset;
int shift;
Scanner scan = new Scanner(System.in);
while (another.equalsIgnoreCase("y"))
{outString=BLANK_STRING;
System.out.print("\nPlease enter a string to be encoded: ");
inString=scan.nextLine();
System.out.print("\nPlease anter a delimited: ");
delimited=scan.nextLine();
System.out.print("\nPlease enter the shift amount: ");
shift=scan.nextInt();
System.out.println("\nEncoding of \"" + inString + "\"");
System.out.println("will be by shifting " + shift + " letter");
inString=inString.toUpperCase();
for (int index=0; index<inString.length(); index++)
{
if(Character.isLetter(inString.charAt(index)))
{
currentLetter=inString.charAt(index);
offset=((currentLetter - FIRST_LETTER) + shift) % ALPHABET_LENGTH;
outLetter=(char)(FIRST_LETTER + offset);
outString=inString.replace(currentLetter,outLetter);
}
}
System.out.println("\nThe encoded string is: \"" + outString.replaceAll(" ",delimited) + "\".");
System.out.print("Enter another one (y/n)? ");
another=scan.nextLine();
}
}
}
你敢不敢让我输入“y”。。魂淡
本帖最后由 jains521 于 2013-4-21 12:44 编辑
木月火石 发表于 2013-4-20 16:49我把那句if的换成
if( inString.charAt(i) >= 'a' || inString.charAt(i) = 'A' || inString.charAt(i) ...
我楼上的已经把重点说了.
我在补充一句.
字符xx满足
(a<= xx <= z) || (A<= xx <=Z)
它们是在什么什么之间的关系. 不是比什么什么大的关系.
所以有如下表达式:
[mw_shl_code=applescript,true](a<= xx && z>=xx) || (A<=xx && Z>=xx)[/mw_shl_code]
[查看全文]
