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.

Results 1 to 2 of 2

Thread: Java student - confusing quiz questions

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Java student - confusing quiz questions

    Hello Java World! I am hoping that someone can clear up some questions for me. I recently took a quiz and I don't understand why a few of my answers were counted wrong. In the following problem:

    Complete this coding to print exactly 3 numbers on every line:
    for (int k = 5;  k < 65;  k++)
     if ( ________________ == 1)     
      System.out.println ("  " + k);
     else    
      System.out.print ("   " + k);

    Why is the answer k%3?

    In the following problem:

    if (x == 5 || y > 2) is fully equivalent to if ( ! ( ________________ ) )

    Why is the answer x != 5 && y <= 2

    In the following problem:

    Complete this if-statement (you may use else) to assign to x the smaller of y and z:

    if (y < z) ________________ ;

    Why is the answer x = y; else x = z

    Also, can you put the else statement and the other on the same line?

    I'm sorry if these questions seem basic but I am just starting out and I want to make sure I understand completely before moving on. Thank you so much for taking the time to help!


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Java student - confusing quiz questions

    Quote Originally Posted by Techstudent View Post
    Complete this coding to print exactly 3 numbers on every line:
    for (int k = 5;  k < 65;  k++)
     if ( ________________ == 1)     
      System.out.println ("  " + k);
     else    
      System.out.print ("   " + k);

    Why is the answer k%3?
    Do you know what is the % operator?

    Quote Originally Posted by Techstudent View Post
    In the following problem:

    if (x == 5 || y > 2) is fully equivalent to if ( ! ( ________________ ) )

    Why is the answer x != 5 && y <= 2
    Do you know De Morgan's laws? (hint: search on Wikipedia)
    This is inherent to boolean algebra.

    Quote Originally Posted by Techstudent View Post
    In the following problem:

    Complete this if-statement (you may use else) to assign to x the smaller of y and z:

    if (y < z) ________________ ;

    Why is the answer x = y; else x = z
    If y is lower than z, what is the smaller? And otherwise?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. The Following User Says Thank You to andbin For This Useful Post:

    GregBrannon (January 14th, 2014)

Similar Threads

  1. Java Quiz help
    By kingsta in forum Java Theory & Questions
    Replies: 2
    Last Post: October 13th, 2013, 10:18 PM
  2. Using Java to create a quiz...
    By purple_ninja in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 7th, 2013, 08:16 AM
  3. How to make a quiz in Java?
    By sly in forum Java Theory & Questions
    Replies: 6
    Last Post: March 18th, 2013, 10:43 AM
  4. Do You Know the Answer to Java Quiz?
    By dblog616 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 13th, 2012, 08:17 PM
  5. Free Java quiz .
    By skoiloth in forum Totally Off Topic
    Replies: 11
    Last Post: January 9th, 2012, 11:16 AM

Tags for this Thread