100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CS 170 CH 05 Midterm || with Error-free Solutions.

Rating
-
Sold
-
Pages
12
Grade
A+
Uploaded on
25-03-2025
Written in
2024/2025

Which of the following options represents the output of the given code snippet? public static int addsub(int a, boolean isSub) { return (isSub ? sub(a) : a + 1); } public static int sub(int a) { return a - 1; } public static void main(String[] args) { Sln("Sub 5 = " + addsub(5, true) + ", Add 6 = " + addsub(6, false)); } correct answers Sub 5 = 4, Add 6 = 7 What is the output of the following Java program? public class Test01 { public static void main(String[] args) { for (int i = 0; i < 4; i++) { S(myFun(i) + " "); } } public static int myFun(int perfect) { return ((perfect - 1) * (perfect - 1)); } } correct answers 1 0 1 4 Given the following method, what method call will return true? public static boolean isValid(String input) { boolean valid = true; if (h() != 11) { valid = false; } else { if (At(3) != '-' || At(6) != '-') { valid = false; }

Show more Read less
Institution
CS 170 CH 05
Course
CS 170 CH 05









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

Written for

Institution
CS 170 CH 05
Course
CS 170 CH 05

Document information

Uploaded on
March 25, 2025
Number of pages
12
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CS 170 CH 05 Midterm || with Error-free Solutions.
Which of the following options represents the output of the given code snippet?

public static int addsub(int a, boolean isSub)
{
return (isSub ? sub(a) : a + 1);
} public static int sub(int a)
{
return a - 1;
}
public static void main(String[] args)
{
System.out.println("Sub 5 = " + addsub(5, true) + ", Add 6 = " + addsub(6, false));
} correct answers Sub 5 = 4, Add 6 = 7

What is the output of the following Java program?
public class Test01
{
public static void main(String[] args)
{
for (int i = 0; i < 4; i++)
{
System.out.print(myFun(i) + " ");
}
}
public static int myFun(int perfect)
{
return ((perfect - 1) * (perfect - 1));
}
} correct answers 1 0 1 4

Given the following method, what method call will return true?
public static boolean isValid(String input)
{
boolean valid = true;
if (input.length() != 11)
{
valid = false;
}
else
{
if (input.charAt(3) != '-' || input.charAt(6) != '-')
{
valid = false;
}

, else
{ valid = Character.isDigit(input.charAt(0)) && Character.isDigit(input.charAt(1)) &&
Character.isDigit(input.charAt(2)) && Character.isDigit(input.charAt(4)) &&
Character.isDigit(input.charAt(5)) && Character.isDigit(input.charAt(7)) &&
Character.isDigit(input.charAt(8)) && Character.isDigit(input.charAt(9)) &&
Character.isDigit(input.charAt(10));
}
}
return valid;
} correct answers isValid("123-45-6789")

Which of the following options represents the output of the given code snippet?

public static int addsub(int a, boolean isSub)
{
if (isSub)
{
return sub(a);
}
else { return a + 1; }
}
public static int sub(int a)
{
return a - 1;
}
public static void main(String[] args)
{
System.out.println("Sub 5 = " + addsub(5, false) + ", Add 6 = " + addsub(6, true));
} correct answers Sub 5 = 6, Add 6 = 5

In the following code snippet, what is the scope of variable b?

public static void m1()
{
int i = 0; double b = 0;
}
public static void m2()
{
double a = b + 1;
}
public static void main(String[] args)
{
m1();
m2();
} correct answers It can be used only in m1.
R200,69
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Document also available in package deal

Get to know the seller

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.
FullyFocus NURSING, ECONOMICS, MATHEMATICS, BIOLOGY, AND HISTORY MATERIALS BEST TUTORING, HOMEWORK HELP, EXAMS, TESTS, AND STUDY GUIDE MATERIALS WITH GUARANTEED A+ I am a dedicated medical practitioner with diverse knowledge in matters
Follow You need to be logged in order to follow users or courses
Sold
734
Member since
3 year
Number of followers
437
Documents
34567
Last sold
2 weeks ago
Reign Supreme Scholarly || Enlightened.

Here we offer revised study materials to elevate your educational outcomes. We have verified learning materials (Research, Exams Questions and answers, Assignments, notes etc) for different courses guaranteed to boost your academic results. We are dedicated to offering you the best services and you are encouraged to inquire further assistance from our end if need be. Having a wide knowledge in Nursing, trust us to take care of your Academic materials and your remaining duty will just be to Excel. Remember to give us a review, it is key for us to understand our clients satisfaction. We highly appreciate clients who always come back for more of the study content we offer, you are extremely valued. All the best.

Read more Read less
3,7

110 reviews

5
46
4
20
3
22
2
8
1
14

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

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

Student with book image

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

Alisha Student

Frequently asked questions