java - 如何在此特定实例中使用 Do-While 循环(程序在 y/n 之前完成)Java
问题描述
我正在做一个需要继续提问的实验室,但无论我做什么,程序总是在接受答案之前停止。这是我的主要方法:
import java.util.Scanner;
import static java.lang.System.*;
public class Lab03b
{
public static void main( String args[] )
{
Scanner scan = new Scanner(in);
boolean ans = true;
do{
out.println("Enter the word to display:: ");
String word = scan.nextLine();
out.println("Enter the number of times to display:: ");
int times = scan.nextInt();
out.println("Do you wish to continue? (y/n):: ");
String choice = scan.nextLine();
WordPrinter.printWord(word,times);
if (choice == "y" || choice == "Y")
{ ans = true;
}
else
{
ans = false;
}
} while(ans == true);
}
}
它引用了另一个类,该类通过基本循环打印出一个单词 x 次。任何帮助表示赞赏。
解决方案
推荐阅读
- c# - 相关方法的通用方法调用
- python - python - 仅当目标中不存在文件时,如何将文件从一个目录复制到另一个目录?
- azure - 如何在没有 Azure 堆栈的情况下通过 API/CLI 创建新的目录租户?
- angular - Angular,2个模块的错误声明,如何解决?
- objective-c - How to access and initialize components of simd types?
- spring - WebSecurityConfig http.logout().addLogoutHandler 不工作
- google-app-engine - Connecting to bank account with OAuth2.0 and Google App Scripts
- jsf - faces-redirect 使用 http 而不是 https
- angular - How can read an excel file which is in the assets folder- Angular?
- python - If Statment in Python while Scraping