I'm currently writing a program that requires me to check several char values using a while statement and I keep getting the error "operator || cannot be applied to char, char". My code works fine with a single value but as soon as I add || or && I get this error. Any help would be greatly appreciated.

String primeColour ;
	primeColour = "none" ;

	String secColour ;
	secColour = "none" ;

	char FColour ;
	FColour = 'N' ;

	char SColour;
	SColour = 'P';

	System.out.print ("\n\nEnter primary colour for car:		") ;
	Colour = user.next().charAt(0);

	while (FColour != ('B' || 'L' || 'W' || 'R' || 'Y' || 'G'))  
	            System.out.print("\nAvaible colors codes are B, L, W, R, Y and G");
	            System.out.print("\nReenter choice for primary colour:		");
	            FColour = user.next().charAt(0); 

Recommended Answers

All 3 Replies

i would create a method called isInSet and you iterate through the characters and check, you can't do a character check the way you are wanting to unless you add them to a list or an array of some sort

You have to compare each one explicitly.

boolean invalidColor = (FColour != 'B' && FColour != 'L' && FColour != 'W' && FColour != 'R' && FColour != 'Y' && FColour != 'G');

Thanks a lot guys, I have 3 assignments I need to finish but I had this same problem with each. So I can final get up to date, again thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.