注意:我的if语句:if(newExteriorColor = availableExteriorColors)在这种情况下不应该使用,因为它不正确,所以只想澄清一下我知道它的错误
如何在availableExteriorColors
数组上进行for循环,以便程序检查所选颜色是否等于数组中的任何String值?
public class Cars {
String [] availableExteriorColors = {"Black", "White", "Blue", "Red", "Yellow", "Brown"};
public static String exteriorColor;
public static String interiorColor;
public static String carBrand;
public static String carModel;
public static String carPlateLetters;
public static String carPlateNumber;
public static int yearOfMake;
//public static ? vinNumber;
public Cars(String newExteriorColor,String newInteriorColor,String newCarBrand,String newCarModel,String newCarPlateLetters,String newCarPlateNumber,int newYearOfMake)
{
if (newExteriorColor = availableExteriorColors)
{
newExteriorColor = exteriorColors;
}
else {
System.out.println("Selected exterior color not available");
return; }
答案 0 :(得分:-1)
for (String color : AvailableExteriorColors) {
if (color.equals(selectedColor)) return color;
}