【发布时间】:2016-10-25 18:50:14
【问题描述】:
我必须解码程序要求输入 1-7 的消息。 1 代表“D”。 2代表“W”。 3代表“E”。 4代表“L”。 5代表“H”。 6代表“O”。 7代表“R”。所以我尝试使用 do-while 循环来扫描我放在一起的字符串,然后一次扫描每个字母,将所述字母添加到解密的字符串中。请帮忙。这是我的代码:
System.out.println("Please enter 10 numbers, after each number you put in, press enter. The numbers can only be from 1 - 7.");
int numInputs = 0;
String code = "", deciphered = "";
int input = 0, charNumber = 1;
do{
System.out.println("Please enter a number: ");
input = in.nextInt();
code+=input;
numInputs++;
}while(numInputs < 10);
System.out.println("Your code is " + code);
do{
switch(code.charAt(charNumber)){
case 1: deciphered+="D";
break;
case 2: deciphered+="W";
break;
case 3: deciphered+="E";
break;
case 4: deciphered+="L";
break;
case 5: deciphered+="H";
break;
case 6: deciphered+="O";
break;
case 7: deciphered+="R";
break;
default: System.out.println("Something went wrong! Try again with numbers only 1 - 7.");
}
charNumber++;
numInputs++;
}while(numInputs < 10);
System.out.println("The output is: "+deciphered);
}
【问题讨论】:
-
请帮忙,什么?您没有表达需要帮助的问题。
-
问题是什么?