Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: If Statements

  1. #1
    katymccl's Avatar
    katymccl is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Question If Statements

    I am working on the practice multiple choice problems for the AP Computer Science exam.

    I came across this question:

    4. At a certain high school students receive letter grades based on the following
    scale.
    Numeric Score Letter Grade
    93 or above A
    From 84 to 92 inclusive B
    From 75 to 83 inclusive C
    Below 75 F

    Which of the following code segments will assign the correct string to grade
    for a given integer score ?

    I. if (score .5 93)
    grade 5 "A";
    if (score .5 84 && score ,5 92)
    grade 5 "B";
    if (score .5 75 && score ,5 83)
    grade 5 "C";
    if (score , 75)
    grade 5 "F";

    II. if (score .5 93)
    grade 5 "A";
    if (84 ,5 score ,5 92)
    grade 5 "B";
    if (75 ,5 score ,5 83)
    grade 5 "C";
    if (score , 75)
    grade 5 "F";

    III. if (score .5 93)
    grade 5 "A";
    else if (score .5 84)
    grade 5 "B";
    else if (score .5 75)
    grade 5 "C";
    else
    grade 5 "F";


    (a) II only
    (b) III only
    (c) I and II only
    (d) I and III only
    (e) I, II, and III

    Letter D is the correct answer. My question is why is II wrong? Wouldn't that code execute fine or is there a problem with the if Statements?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: If Statements

    What language is that code? it certainly isn't valid Java code.

    db
    Bestsanchez likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    katymccl's Avatar
    katymccl is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: If Statements

    well it's java. but this isn't the entire code. its just the question. its like a part of a bigger program we don't get to see i guess. We are just supposed to say whether I, II, III or all of them would complete the task. Does that clear things up?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: If Statements

    Quote Originally Posted by katymccl View Post
    well it's java.
    No, it isn't.

    but this isn't the entire code. its just the question.
    If there's no code, it isn't Java. Nor any other programming language.

    Heck, what you posted can't even be considered valid pseudocode.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: If Statements

    At a guess, I would say you lazily copied that from a source which used images for mathematical operators, and the images didn't get pasted here. And you didn't bother to replace them with their textual equivalents either.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    ShaolinMunky is offline Computer Science Student
    Join Date
    Feb 2012
    Location
    Savannah, GA
    Posts
    4
    Rep Power
    0

    Default Re: If Statements

    I think the problem is with the logic in the if statement parameters. Someone correct me if I'm wrong, but you can't chain logic the way it's chained in II. You have to define the left separate from the right. That is, you can't use "5 < x < 10" but have to state "5 < x" and "x < 10."

    --SM

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,019
    Blog Entries
    7
    Rep Power
    20

    Default Re: If Statements

    My guess is that ".5" means ">=" and ",5" means "<="; the text was probably copied some way from an image; the OP should've checked the results ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. if else if statements
    By Allspark in forum New To Java
    Replies: 9
    Last Post: 09-28-2010, 06:50 PM
  2. Help with if else statements
    By np2392 in forum New To Java
    Replies: 2
    Last Post: 09-24-2010, 01:25 AM
  3. if else statements
    By sweetpea123 in forum New To Java
    Replies: 4
    Last Post: 04-12-2010, 07:02 PM
  4. age: using if statements
    By yasmin k in forum New To Java
    Replies: 2
    Last Post: 10-04-2009, 09:50 PM
  5. Help with if-else statements
    By porchrat in forum New To Java
    Replies: 4
    Last Post: 03-23-2009, 04:24 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •