我在编写代码时遇到问题,只要用户没有结束"退出",就会生成一个while循环请求用户输入.当我运行代码时,它只生成第一个提示问题"输入一个句子或一个短语:",然后在输入短语后它不会计算while语句.有谁知道我做错了什么?
问题是:"让程序让用户继续输入短语而不是每次都重新启动它会很好.为此,我们需要围绕当前代码的另一个循环.也就是说,当前循环将嵌套在里面新的循环.添加一个外部while循环,只要用户没有输入短语quit就会继续执行.修改提示以告诉用户输入短语或退出退出.注意所有的初始化count应该在while循环中(也就是说我们希望用户输入的每个新短语重新开始计数).你需要做的就是添加while语句(并考虑读取的位置以便循环正常工作)确保完成程序并在添加代码后正确缩进 - 使用嵌套循环时,内循环应缩进."
import java.util.Scanner;
public class Count
{
public static void main (String[] args)
{
String phrase; // A string of characters
int countBlank; // the number of blanks (spaces) in the phrase
int length; // the length of the phrase
char ch; // an individual character in the string
int countA, countE, countS, countT; // variables for counting the number of each letter
scan = new Scanner(System.in);
// Print a program header
System.out.println ();
System.out.println ("Character Counter"); …Run Code Online (Sandbox Code Playgroud)