Test: Computer Science

1.

Which of the following code samples adequately uses constants?

for(final int i = 0, rows = 5; i < rows; i++) {

    System.out.println(i);

}

final int rows;

int intVal;

// Variable intVal read in during this code.... Excerpted...

rows = intVal;

for(int i = 0; i < rows; i++) {

    System.out.println(i);

}

 

final int rows = 4;

for(int i = 0,l = rows; i < l; i++) {

    rows += 2;

}

final String s = "Hello, "

int intVal;

// Variable intVal read in during this code.... Excerpted...

if(intVal < 0) {

    s += "World!";

} else if(intVal == 0) {

    s += "People!";

} else {

    s += "Folks!";

}

const int rows = 4;

for(int i = 0; i < rows; i++) {

    System.out.println(i);

}

 

1/2 questions

0%

Access results and powerful study features!

Take 15 seconds to create an account.
Start now! Create your free account and get access to features like:
  • Full length diagnostic tests
  • Invite your friends
  • Access hundreds of practice tests
  • Monitor your progress over time
  • Manage your tests and results
  • Monitor the progress of your class & students
By clicking Create Account you agree that you are at least 13 years old and you agree to the Varsity Tutors LLC Terms of Use and Privacy Policy.
Learning Tools by Varsity Tutors