GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

GradePack

Consider the problem of finding the maximum value in an arra…

Consider the problem of finding the maximum value in an array of integers. The following code segments are proposed solutions to the problem. Assume that the variable arr has been defined as an array of int values and has been initialized with one or more values. Which of the code segments will always correctly assign the maximum element of the array to the variable max ?

Read Details

A student has created a Song class. The class contains the f…

A student has created a Song class. The class contains the following variables. A String variable called artist to represent the artist name A String variable called title to represent the song title A String variable called album to represent the album title The object happyBirthday will be declared as type Song. Which of the following statements is true?

Read Details

Consider the following methods, which appear in the same cla…

Consider the following methods, which appear in the same class. public void slope(int x1, int y1, int x2, int y2) { int xChange = x2 – x1; int yChange = y2 – y1; printFraction(yChange, xChange); }     public void printFraction(int numerator, int denominator) { System.out.print(numerator + “/” + denominator); } Assume that the method call slope(1, 2, 5, 10) appears in a method in the same class. What is printed as a result of the method call?

Read Details

Consider the following class definition. public class ExamS…

Consider the following class definition. public class ExamScore { private String studentId; private double score;   public ExamScore(String sid, double s) { studentId = sid; score = s; }   public double getScore() { return score; }   public void bonus(int b) { score += score * b/100.0; } } Assume that the following code segment appears in a class other than ExamScore. ExamScore es = new ExamScore(“12345”, 80.0); es.bonus(5); System.out.println(es.getScore()); What is printed as a result of executing the code segment?

Read Details

A student has created a Car class. The class contains variab…

A student has created a Car class. The class contains variables to represent the following. A String variable called color to represent the color of the car An int variable called year to represent the year the car was made A String variable called make to represent the manufacturer of the car A String variable called model to represent the model of the car The object vehicle will be declared as type Car. Which of the following descriptions is accurate?

Read Details

Consider the following code segment. int num1 = 0; int num2…

Consider the following code segment. int num1 = 0; int num2 = 3; while ((num2 != 0) && ((num1 / num2) >= 0)) {   num1 = num1 + 2;   num2 = num2 – 1; } What are the values of numl and num2 after the while loop completes its execution?

Read Details

Consider the following method. public int mystery(int num) {…

Consider the following method. public int mystery(int num) { int x = num; while (x > 0) { if (x / 10 % 2 == 0) return x; x = x / 10; } return x; } What value is returned as a result of the call mystery(1034) ?

Read Details

Consider the following code segment. int k = 1; while (k < 2...

Consider the following code segment. int k = 1; while (k < 20) {   if ((k % 3) == 1)     System.out.print(k + " ");     k++; }   What is printed as a result of executing this code segment?

Read Details

Consider the following two code segments. Code segment II is…

Consider the following two code segments. Code segment II is a revision of code segment I in which the loop header has been changed. I. for (int k = 1; k = 1; k–) { System.out.print(k); } Which of the following best explains how the output changes from code segment I to code segment II?

Read Details

Consider the following method. public String wordPlay(Strin…

Consider the following method. public String wordPlay(String word) { String str = “”; for (int k = 0; k < word.length(); k++) { if (k % 3 == 0) { str = word.substring(k, k + 1) + str; } } return str; } The following code segment appears in another method in the same class as wordPlay. System.out.println(wordPlay("Computer Science")); What is printed as a result of executing the code segment?

Read Details

Posts pagination

Newer posts 1 … 38,048 38,049 38,050 38,051 38,052 … 68,196 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top