Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27

Thread: Assignment Problem. Please help

  1. #26
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Assignment Problem. Please help

    Quote Originally Posted by melki0795 View Post
    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 View Post
    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.

  2. #27
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Assignment Problem. Please help

    Quote Originally Posted by melki0795 View Post
    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:
    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 View Post
    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.
    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();
        }
    }
    Improving the world one idiot at a time!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. New assignment new problem...
    By tyeeeee1 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 24th, 2012, 03:00 PM
  2. Problem with School Assignment.
    By SaltSlasher in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 13th, 2012, 08:22 AM
  3. BankAccount assignment problem
    By ddonn in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 6th, 2011, 01:04 PM
  4. Problem with code for school assignment?
    By Mellisa315 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 16th, 2010, 09:36 PM
  5. Assignment problem.
    By minou13 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 26th, 2010, 10:51 PM

Tags for this Thread