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

CODEHS AP COMPUTER SCIENCE A (Nitro) ITERATION QUIZ QUESTIONS WITH 100% CORRECT ANSWERS!!

Rating
-
Sold
-
Pages
9
Grade
A+
Uploaded on
07-05-2024
Written in
2023/2024

CODEHS AP COMPUTER SCIENCE A (Nitro) ITERATION QUIZ QUESTIONS WITH 100% CORRECT ANSWERS!!

Institution
CODEHS AP COMPUTER SCIENCE
Module
CODEHS AP COMPUTER SCIENCE









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

Written for

Institution
CODEHS AP COMPUTER SCIENCE
Module
CODEHS AP COMPUTER SCIENCE

Document information

Uploaded on
May 7, 2024
Number of pages
9
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CODEHS AP COMPUTER SCIENCE A (Nitro)
ITERATION QUIZ QUESTIONS WITH 100%
CORRECT ANSWERS!!
QUESTION 1:
Write a method that loops until the user inputs the correct secret password or
until the user fails to enter the correct password 10 times. The secret password
the program should look for is the String "secret"

Assume that a Scanner object called input has been correctly initialized.
ANSWER: C
public void secretPassword()
{
int count = 0;
while(true)
{
if(count == 10)
{
System.out.println("You are locked out!");
return;
}
String readLine = input.nextLine();
if(readLine.equals("secret"))
{
System.out.println("Welcome!");
return;
}

count++;
}
}
QUESTION 2:
What would the method call myMethod("Karel The Dog", 'e') output?

public int myMethod(String x, char y)
{
int z = 1;
for(int i = 0; i < x.length(); i++)
{
if(x.charAt(i) == y)
{
z++;
}
}

, return z;
}
ANSWER: C
3
QUESTION 3:
What kind of error would the method call myMethod("Frog") cause?

public void myMethod(String x)
{
for(int i = 0; i <= x.length(); i++)
{
System.out.println(x.substring(i, i+1));
}
}
ANSWER: B
Runtime Error: String index out of range
QUESTION 4:
What will the call to the method funWithNumbers(314159) print to the screen?

public void funWithNumbers(double myDouble)
{
int myInt = (int) myDouble;
String myString = "";
while(myInt != 0)
{
myString = myInt % 10 + myString;
myInt /= 10;
}
System.out.println(myString);
}
ANSWER: A
314159
QUESTION 5:
What does the call to the method someMethod(3,1) output?

public int someMethod(int x, int y)
{
int sum = 0;
while (x < 10)
{
sum += x % y;
x++;
y++;
}
return sum;
}

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.
Aplusplus Havard School
View profile
Follow You need to be logged in order to follow users or courses
Sold
3819
Member since
1 year
Number of followers
89
Documents
6022
Last sold
4 days ago
GOLD REPUTATION

PREMIUM DOCUMENTS. GREAT REVIEWS Many students don't have the time to work on their academic papers due to balancing with other responsibilities, for example, part-time work. I can relate. kindly don't hesitate to contact me, my study guides, notes and exams or test banks, are 100% graded

4.6

243 reviews

5
210
4
9
3
9
2
0
1
15

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 revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight 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 smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions