Ask Question
10 January, 21:35

Can you structure this code in if-statements?

public int getData (int dataNumber)

{

switch (dataNumber)

{

case 1: return quizScore1;

case 2: return quizScore2;

case 3: return quizScore3;

default: return (Integer) null;

}

}

+1
Answers (1)
  1. 10 January, 22:24
    0
    Not sure what quizScore1-5 is, but here it is. Also, I'm not entirely sure what language you're working with here, but null can't be returned as an integer. If it were a string, for example, it'd be possible as string is an object reference type.

    public int getData (int dataNumber)

    {

    if (dataNumber = = 1)

    return quizScore1;

    else if (dataNumber = = 2)

    return quizScore2;

    else if (dataNumber = = 3)

    return quizScore3;

    else if (dataNumber = = 4)

    return quizScore4;

    else if (dataNumber = = 5)

    return quizScore5;

    else

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Can you structure this code in if-statements? public int getData (int dataNumber) { switch (dataNumber) { case 1: return quizScore1; case ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers