A+ 2025/2026
What does the method call tripleString("APCSA"); return for the following method?
public String tripleString(String x)
{
return x * 3;
} - This method is improperly written.
What will the value of myBankAccount be after the method call
depositMoney(myBankAccount, 572);?
int myBankAccount = 122; public void depositMoney(int bankAccount, int deposit)
{
bankAccount += deposit;
} - 122
What is returned by this method call: translator("pokemon")?
public String translator(String word)
{
return word.substring(1) + word.substring(0,1) + "ay";
} - "okemonpay"
What will this method call print to the screen?
public static void formatText(int a, int b, String c)
{
System.out.println(b + " " + c + ", " + a);
}
formatText(2018, 17, "Dec") - 17 Dec, 2018
What is wrong with this method definition?
public int printPayAmount(int amount)
{
System.out.println(amount);
} - Nothing is returned from this method
Why do we use methods in Java?
I. To make code easier to understandII. To define global variablesIII. To avoid repeated
codeIV. To simplify codeV. To avoid needing to define them as public or private - I, III,
and IV
A coffee shop has created a DrinkOrder class. The class contains variables to represent
the following:
A String variable called name to represent the name of the drink.
An int variable called ounces to indicate how many ounces the drink should be.
A boolean variable called isIced to indicate whether the drink is iced.