6。)情景 - 你正和你的小表弟一起玩猜谜游戏。她想让你猜出她最喜欢的颜色。使用While循环创建程序。下面是我写的代码但是在while循环中遇到了问题。
package loopscenario;
import java.util.Scanner;
import java.util.Random;
/**
*
* @author macbook
*/
public class LoopScenario6 {
public static void main(String[] args)
{
String blue = null;
String yellow = null ;
String red = null;
String pink = "pink";
String favoriteColor = null;
Scanner keyboard = new Scanner(System.in);
Random randomNumber = new Random();
Random aRan = new Random();
while (!favoriteColor.equalsIgnoreCase(pink))
if (favoriteColor.equalsIgnoreCase(blue))
{
System.out.println("Wrong color. Please try again.");
}
else if( favoriteColor.equalsIgnoreCase(yellow))
{
System.out.println("Wrong color. Please try again.");
}
else if ( favoriteColor.equalsIgnoreCase(red))
{
System.out.println("Wrong color. Please try again.");
}
else
{
System.out.println("Yes!");
}
}
}