Re: Assignment Problem. Please help
Quote:
Originally Posted by
melki0795
i think by listing them down as 1 condition would be unprofessional.
Not so. Code readability is important but clarity != short.
Quote:
Originally Posted by
melki0795
Code java:
if (!Selection.equals("A") & !Selection.equals("B") & !Selection.equals("C")){
Once again you are trying to use bitwise & for a logical statement. Please see Learning the Java Language > Language Basics > Operators. Logical AND is two ampersands '&&' and is used to join two conditions together. Bitwise AND is one apersand '&' and it performs an AND on the individual bits in the variable. Bitwise AND has no place in a conditional unless you are bit twiddling.
Re: Assignment Problem. Please help
Quote:
Originally Posted by
melki0795
i think that listing a statement something like that all the way to F would be messy....
Here's a hint to an easier way:
Code :
char first = 'b';
char second = 'z';
System.out.println(first >= 'a' && first <= 'c');
System.out.println(second >= 'a' && second <= 'c');
--- Update ---
Quote:
Originally Posted by
ChristopherLowe
Once again you are trying to use bitwise & for a logical statement.
Actually using a single ampersand is fine as long as you know the consequences. Run the following code.
Code :
class BooleanTest {
private boolean methodOne() {
System.out.println("Method one");
return false;
}
private boolean methodTwo() {
System.out.println("Method two");
return false;
}
public void run() {
if(methodOne() && methodTwo()) {
System.out.println("Foo");
}
System.out.println();
if(methodOne() & methodTwo()) {
System.out.println("Foo");
}
}
public static void main(String[] args) {
new BooleanTest().run();
}
}