ここに私が与えられた問題があります: ユーザーが単語「停止」をタイプするまでキーボード入力としてウェブサイト名を取るプログラムを書く。プログラムmは、商用ウェブサイト名(すなわち、.comで終わる)のウェブサイト名の数もカウントし、その数を出力するだけである。ウェブサイトをキーボード入力として使用していますか?
問題が発生し続けるということは、入力として「停止」という単語を入力しても、「次のサイトに入る」ということです。どこが間違っているのか分かりません。
誰でも手助けできますか?ここに私のコードです。
import java.util.Scanner;
public class NewClass
{
public static void main(String [] args)
{
int numberOfComSites = 0;
String commercialNames = "com";
final String SENTINEL = "stop";
String website;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a website, or 'stop' to stop > ");
website = scan.next();
String substring = website.substring(website.length()-3);
while (website != SENTINEL)
{
if(substring == commercialNames)
{ numberOfComSites++;
}
System.out.print("Enter the next site > ");
website = scan.next();
}
System.out.println("You entered" + numberOfComSites + "commercial websites.");
}
}
ありがとうございます!