我基本上试图允许用户能够在Gradebook(数组)中多次改变他们想要的(元素)等级(基本上是循环)。我已经给用户提供了输入索引的选项(应该从1开始而不是0,以避免混淆用户)但是在这一步之后我被卡住了。我不确定如何搜索数组中的元素,然后要求用户替换它......
到目前为止,这是我的代码:
public async Task TaskRun(CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
SpeechSynthesizer _speechSynthesizer = new SpeechSynthesizer();
using (ct.Register(() => _speechSynthesizer.SpeakAsyncCancelAll())) {
await _speechSynthesizer.SpeakAsync("This is a test prompt");
}
}
任何帮助将不胜感激。
答案 0 :(得分:0)
结构应与此类似:
System.out.println("___________________________");
System.out.println("Make changes? Enter Y or N");
String makeChanges = System.console().readLine();
while (makeChanges.equals("Y")) {
//Ask user if what grade they would like to change
int index = NumberReader.readPositiveInt(input,
"Enter the index of the grade to be changed: (1 to " + grades + ") : ", "Invalid index input");
System.out.println("Enter grade (limit to two decimal places)" + index + ": ");
//offset the index by one
mogrades[index - 1] = NumberReader.readPositiveDouble(input, "Enter grade " + index + " :", "Invalid data entered");
System.out.println("Make changes? Enter Y or N");
makeChanges = System.console().readLine();
}
}
您希望在他们仍想进行更改时继续循环。