GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

Author Archives: Anonymous

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

Consider the following method. public static String changeS…

Consider the following method. public static String changeStr(String str) { String result = “”; for (int i = str.length() – 1; i >= str.length() / 2; i -= 2) { result += str.substring(i, i + 1); } return result; } What value is returned as a result of the method call changeStr(“12345”) ?

Read Details

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

Consider the following code segment. int j = 1; while (j < 5) { int k = 1; while (k < 5) { System.out.println(k); k++; } j++; } Which of the following best explains the effect, if any, of changing the first line of code to int j = 0; ?

Read Details

Posts pagination

Newer posts 1 … 44,950 44,951 44,952 44,953 44,954 … 75,098 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top