• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 38 pages
Exam (elaborations)

Midterm I Exam Key Study Guide CMSC 201 - Practice-Ready Answer Guide

Document preview thumbnail
Preview 4 out of 38 pages

Midterm I Exam Key Study Guide CMSC 201 - Practice-Ready Answer Guide Which of the following statement is incorrect? b = 40; s = 200; i = 200; j = 200L; - answer - j = 200L; What is item after the following loop terminates? ( line numbers are not a feature of a code) 1: int sum = 0; 2: int item = 0; 3: do { 4: item += 1; 5: sum += item; 6: if (sum 4) 7: break; 8: } while (item 5); - answer - item = 3; "AbA".compareToIgnoreCase("abC") returns ________. - answer - -2 Convert the following for loop into a do-while loop int sum = 0; for (int i = 0; i 100; i++) { sum += i; } - answer - int sum = 0; int i = 0; do { sum +=i; i++; } while(i 100); According to Java naming convention, which of the following is a constant? 1. MAXINTEGER 2. MAX-INTEGER 3. max_integer 4. MAX_INTEGER 5. max-integer - answer - 4. MAX_INTEGER (Sort three numbers) Write a method with the following header to display threenumbers in increasing order (one blank space between numbers): public static void displaySortedNumbers(double num1, double num2, double num3) Add a main method to the class that prompts for three numbers that are sent to the displaySortedNumbersmethod. Sample output: Enter·the·three·numbers:1.1·3.4·2.3↵ ·1.1·2.3·3.4↵ - answer - import .Scanner; public class SortedNumbers { public static void displaySortedNumbers(double num1, double num2, double num3) { double t; if (num1 num2) { t = num1; num1 = num2; num2 = t; } if (num1 num3) { t = num1; num1 = num3; num3 = t; } if (num2 num3) { t = num2; num2 = num3; num3 = t; } Sln(num1 + " " + num2 + " " + num3); } public static void main(String [] args) { Scanner s = new Scanner(S); S("Enter the three numbers: "); double num1 = Double(); double num2 = Double(); double num3 = Double(); displaySortedNumbers(num1, num2, num3); } } Use a switch statement to rewrite the following if statement // Find interest rate based on year if (numOfYears == 7) annualInterestRate = 7.25; else if (numOfYears == 15) annualInterestRate = 8.50; else if (numOfYears == 30) annualInterestRate = 9.0; else { Sln("Wrong number of years"); S(0); } - answer - switch (numOfYears) { case 7: annualInterestRate = 7.25; break; case 15: annualInterestRate = 8.50; break; case 30: annualInterestRate = 9.0; break; default: Sln("Wrong number of years"); S(0); } Does the return statement in the following method cause compile errors? public static void main(String[] args) { int max = 0; if(max != 0) { System.Out.Println(max); } else return; - answer - No Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? 1 x 100 && x 0 ((x 100) && (x 1)) || (x 0) ((x 100) && (x 1)) && (x 0) (1 x 100) || (x 0) - answer - ((x 100) && (x 1)) || (x 0) Write a main method to let a user enter student scores, and display the max, min, and average of the score. The input 0 signifies the end of input. - answer - .Scanner; public class Calcscore { public static void main (string[] args) { Scanner input = new Scanner( ); S(" enter student scores (the input ends when you enter 0: "); double score = Double(); double sum = 0.0; int count = 0; double max; double min; while (score != 0) { sum += score; count ++; if ( score max ) max = score; if (score min) min = score; S(" enter student scores (the input ends when you enter 0: "); double score = Double(); } double average = sum / (double) count; S. println(" the average is: " + average); Sln("the maximum score is: " + max); Sln("the minimum score is: " + min); } } In the code below, what are the possible types for the variable result? Choose the most


Document information

Uploaded on
November 12, 2026
Number of pages
38
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$13.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
aldrisraand
3.0
(1)
Sold
21
Followers
0
Items
10513
Last sold
13 hours ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions

Whoops! We can’t load your doc right now. Try again or contact support.