100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CMSC 201 - Final Exam/ Updated/ A+ Graded already $13.99   Add to cart

Exam (elaborations)

CMSC 201 - Final Exam/ Updated/ A+ Graded already

 5 views  0 purchase
  • Course
  • Institution

CMSC 201 - Final Exam/ Updated/ A+ Graded already

Preview 4 out of 63  pages

  • September 5, 2023
  • 63
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
avatar-seller
CMSC 201 - Final Exam/ Updated/ A+
Graded already
Which of the following statement is incorrect?
1.byte b = 40;
2.short s = 200;
3.int i = 200;
4.int j = 200L; - -4.int 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); - -item = 3;


-"AbA".compareToIgnoreCase("abC") returns ________. - --2


-Convert the following for loop into a do-while loop
int sum = 0;
for (int i = 0; i< 100; i++)
{

,sum += i;
} - -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 - -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↵ - -import
java.util.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;
}
System.out.println(num1 + " " + num2 + " " + num3);
}
public static void main(String [] args)
{
Scanner s = new Scanner(System.in);
System.out.print("Enter the three numbers: ");

, double num1 = s.nextDouble(); double num2 =
s.nextDouble(); double num3 = s.nextDouble();
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
{
System.out.println("Wrong number of years");
System.exit(0);
} - -switch (numOfYears)
{
case 7: annualInterestRate = 7.25;
break;
case 15: annualInterestRate = 8.50;
break;
case 30: annualInterestRate = 9.0;

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller NurseSallyD. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $13.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79202 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$13.99
  • (0)
  Add to cart