• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/49

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

49 Cards in this Set

  • Front
  • Back

20554: Given the char variable c, write an expression that is true if and only if the value of c is not the space character.

c != ' '

20552: Write an expression that evaluates to true if and only if the value of the integer variable x is equal to zero.

x == 0

20553: Write an expression that evaluates to true if and only if the variables profits and losses are exactly equal.

profits == losses

20667: Write an expression that evaluates to true if the integer variable x contains an even value, and false if it contains an odd value.

x%2 == 0

20665: Write an expression that evaluates to true if the value of the integer variable numberOfPrizes is divisible (with no remainder) by the integer variable numberOfParticipans. Assume that numberOfParticipants is not zero.

numberOfPrizes%numberOfParticipants == 0

20890: Assume that c is a char variable has been declared and already given a value. Write an expression whose value is true if and only if c is a newline character.

c == '\n'

20608: Write an expression that evaluates to true if and only if the integer x is greater than the integer y.

x > y

20556: Working overtime is defined as having worked more than 40 hours during the week. Given the variable hoursWorked, write an expression that evaluates to true if the employee worked overtime.

hoursWorked > 40

20559: Given a double variable called average, write an expression that is true if and only if the variable’s value is less than 60.0.

average<60.0

20560: Given an int variable grossPay, write an expression that evaluates to true if an donly if the value of grossPay is less than 10,000.

grossPay<10000


(DON'T PUT COMMA)

20920: Assume that x is a char variable has been declared and already given a value. Write an expression whose value is true if and only if x is NOT a letter.

!(x>='a' && x<='z') && !(x>='A' && x<='Z')

20561: Given that the variables x and y have already been declared and assigned values, write an expression that evaluates to true is x is non-negative and y is negative.

x >= 0 && y < 0

20563: Given two variables, isEmpty of type boolean, indicating whether a class roster is empty or not, and numberOfCredits of type int, containing the number of credits for a class, write an expression that evaluates to true if the class roster is empty or the class is exactly three credits.

(isEmpty == true) || (numberOfCredits == 3)

20564: Given two variables, isEmpty of type boolean, indicating whether a class roster is empty or not, and numberOfCredits of type int, containing the number of credits for a class, write an expression that evaluates to true if the class roster is not empty and the class is more than two credits.

(isEmpty != true) && (numberOfCredits > 2)

20565: Given two variables, isEmpty of type boolean, indicating whether a class roster is empty or not, and numberOfCredits of type int, containing the number of credits for a class, write an expression that evaluates to true if the class roster is not empty and the class is one or three credits.

(isEmpty != true) && (numberOfCredits==1 || numberOfCredits==3)

20893: Assume that c is a char variable has been declared and already given a value. Write an expression whose value is true if and only if c is what is called a whitespace character (that is a space or a tab or a newline—none of which result in ink being printed on paper).

(c == ' ') || (c == '\t') || (c == '\n')

20894: Assume that c is a char variable has been declared and already given a value. Write an expression whose value is true if and only if c is NOT what is called a whitespace character (that is a space or a tab or a newline—none of which result in ink being printed on paper).

(c != ' ') && (c != '\t') && (c != '\n')

20613: Write an expression that evaluates to true if and only if value of the boolean variable isAMember is false.

isAMember != true

20673: Write a statement that toggles the value of onOffSwitch. That is, if onOffSwitch is false, its value is changed to true; if onOffSwitch is true, its value is changed to false.

if (onOffSwitch==false)
onOffSwitch=true;
else
onOffSwitch=false;

20921: Assume that a boolean variable isQuadrilateral has been declared, and that another variable, numberOfSides has been declared and initialized. Write a statement that assigns the value true if numberOfSides is exactly 4 and false otherwise.

if (numberOfSides == 4)


isQuadrilateral = true;


else


isQuadrilateral = false;


(boolean... "=" は一つだけ)

20946: Clucker Motors Inc. is recalling all vehicles from model years 2001-2006. A boolean variable named norecall has been declared. Given a variable modelYear write a statement that assigns true to norecall if the value of modelYear does NOT within the recall range and assigns false otherwise. Do not use an if statement in this exercise!

norecall = !(modelYear >=2001 && modelYear <=2006);

20941: Clunker Motors Inc is recalling all vehicles from model years 1995-1998 and 2004-2006. A boolean variable named recalled has been declared. Given a variable modelYear write a statement that assigns true to recalled if the value of modelYear falls within the two recall ranges and assigns false otherwise. Do not use an if statement in this exercise!

recalled = (modelYear >=1995 && modelYear <= 1998) || (modelYear >= 2004 && modelYear <= 2006);

20942: Clunker Motos Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. A boolean variable named recalled has been declared. Given a variable modelYear write a statement that assigns true to norecall if the valueof modelYear does NOT fall within the two recall ranges and assigns false otherwise. Do not use an if statement in this exercise!

norecall = !(modelYear >=1995 && modelYear <= 1998) && !(modelYear >= 2004 && modelYear <= 2006);

20756: Assign to the boolean variable ‘possibleCandidate’ the value false if the int variable ‘n’ is even and greater than 2, or if the variable ‘n’ is less than or equal to 0; otherwise, assign true to ‘possibleCandidate’. Assume ‘possibleCandidate’ and ‘n’ are already declared and ‘n’ assigned a value.

if (((n%2 == 0) && (n>2)) || (n <= 0))
possibleCandidate = false;
else
possibleCandidate = true;

20616: Write a conditional that decreases the variable shelfLife by 4 if the variable outside Temperature is greater than 90.

if (outsideTemperature > 90)
shelfLife = shelfLife -4;

20617: Write a conditional that multiplies the value of the variable pay by one-and-a-half if the value of the boolean variable workedOvertime is true.

if (workedOvertime == true)
pay = pay * 1.5;


(true/false は、イコール2つ)

20932: Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. Given a variable modelYear write a statement that prints the message “RECALL” to standard output if the value of modelYear falls within those two ranges.

if ((modelYear>=1995 && modelYear<=1998) || (modelYear>=2004 && modelYear<=2006))
System.out.println("RECALL");

20927: Assume that the variables gpa, deansList and studentName, have been declared and initialized. Write a statement that adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.

if (gpa > 3.5)
{
deansList = deansList + 1;
System.out.println(studentName);
}

20934: Clunker Motors Inc is recalling all vehicles in its Extravagent line from model years 1999-2002. A boolean variable named recalled has been declared. Given a variable modelYear and a String modelName write a statement that assigns true to recalled is the values of modelYear and modelName match the recall details and assigns false otherwise.

if ((modelYear>=1999 && modelYear<=2002) && (modelName == "Extravagant"))
recalled = true;
else
recalled = false;



(modelName... イコール二つ、""をつける)

20945: Clunker Motors Inc. is recalling all vehicles from model years 2001-2006. Given a variable modelYear write a statement that prints the message “NO RECALL” to standard output if the value of modelYear DOES NOT fall within that range.

if (!(modelYear>=2001 && modelYear<=2006))
System.out.println("NO RECALL");

20619: Write an if/else statement that compares the value of the variables soldYesterday and soldToday, and based upon that comparison assigns salesTrend the value -1 or 1. -1 represents the case where soldYesterday is greater than soldToday; 1 represents the case where soldYesterday is not greater than soldToday.

if (soldYesterday > soldToday)


salesTrend = -1;


else


salesTrend = 1;

A String variable , fullName, contains a name in one of two formats:


last name , first name (comma followed by a blank), or


first name last name (single blank)



Extract the first name into the String variable firstName and the last name into the String variable lastName. Assume the variables have been declared and fullName already initialized . You may also declare any other necessary variables .

int a = 0;


a = fullName.indexOf(",");


int b = 0;


b = fullName.indexOf(" ");


if (a > 0)


{


lastName = fullName.substring(0,a);


firstName = fullName.substring(a+2,fullName.length());


}


else


{


firstName = fullName.substring(0,b);


lastName = fullName.substring(b+1,fullName.length());


}

20933: Clunker Motors Inc. is recalling all vehicles in its Extravagent line from model years 1999-2002. Given a variable modelYear and a String modelName write a statement that prints the message “RECALL” to standard output if the values of modelYear and modelName match the recall details.

if (modelYear >= 1999 && modelYear <= 2002)


{


if (modelName == "Extravagant")


System.out.println("RECALL");


}

Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with every purchase of 8 or more books. It offers regular customers 1 free book with every purchase of 7 or more books, and offers 2 free books with every purchase of 12 or more books. Write a statement that assigns freeBooks the appropriate value based on the values of the boolean variable isPremiumCustomer and the int variable nbooksPurchased.

freeBooks = 0;


if (isPremiumCustomer == true)


{


if (nbooksPurchased >= 5) freeBooks = 1;


if (nbooksPurchased >= 8) freeBooks = 2;


}


else


if (isPremiumCustomer == false)


{


if (nbooksPurchased >= 7) freeBooks = 1;


if (nbooksPurchased >= 12) freeBooks = 2;


}

20938: NOTE: in mathematics, the square root of a negative number is not real; in Java therefore, passing such a value to the square root functions returns a value known as NaN (not-a-number). Given a double variable named areaOfSquare, write the necessary code to read in a value, the area of some square, into areaOfSquare and print out the length of the side of that square. HOWEVER: if any value read in is not valid input, just print the message “INVALID”. ASSUME the availability ofa variable stdin, that references a Scanner object associated with standard input.

areaOfSquare = stdin.nextDouble();


if (areaOfSquare < 0)


System.out.print("INVALID");


else


System.out.print(Math.sqrt(areaOfSquare));

20939: NOTE: in mathematics, division by zero is undefined. So, in Java, division by zero is always an error. Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values into callsReceived and operatorsOnCall and print out the number of calls received per operator (integer division with truncation will do. HOWEVER: if any value read in is not valid input, just print the message “INVALID”. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.

callsReceived = stdin.nextInt();


operatorsOnCall = stdin.nextInt();


if (operatorsOnCall == 0)


System.out.print("INVALID");


else


System.out.print(callsReceived/operatorsOnCall);

20940: Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessary code to read a value into response and then carry out the following: if the value tyoped in is a 1 or a 2 then increment yesCount and print out “YES WAS RECORDED”. if the value typed in is a 3 or a 4 then increment noCount and print out “NO WAS RECORDED” If the input is invalid just print the message “INVALID” and do nothing else. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.

response = stdin.nextInt();


if (response == 1 || response == 2)


{


yesCount++;


System.out.print("YES WAS RECORDED");


}


else if (response == 3 || response == 4)


{


noCount++;


System.out.print("NO WAS RECORDED");


}


else


System.out.print("INVALID");

20936: Clunker Motos Inc. is recalling all vehicles in its Extravagant line from model years 1999-2002 as well as all vehicles in its Guzzler line from model years 2004-2007. A boolean variable named recalled has been declared. Given a variable modelYear and a String modelName write a statement that assigns true to recalled if the values of modelYear and modelName match the recall details and assigns false otherwise.

if ((modelYear >= 1999 && modelYear <= 2002 && modelName == "Extravagant")||(modelYear >= 2004 && modelYear <=2007 && modelName == "Guzzler"))


{


recalled = true;


}


else


recalled = false;

20599: Write an expression that evaluates to true if the value of the string variable s1 is greater than the value of string variable s2.

(s1.compareTo(s2)>0)

20600: Write an expression that evaluates to true if the value of variable lastName is greater than the string Dexter.

(lastName.compareTo("Dexter")>0)

20603: Given the string variables name1, name2, and name3, write a fragment of code that assigns the largest value to the variable max (assume all three have already been declared and have been assigned values).

if (name1.compareTo(name2)>0)


max = name1;


else


max = name2;


if (name3.compareTo(max)>0)



max = name3;

20965: Assume that s is a String. Write an expression whose value is true if and only if the value of s would come between “mortgage” and “mortuary” in the dictionary.

(s.compareTo("mortgage")>0) && (s.compareTo("mortuary")<0)

60114: Difference in UNICODE value between ‘e’ and ‘a’



Difference in UNICODE value between ‘3’ and ‘0’

4


3

20902: Assume that x is a char variable that has been declared and already given a value. Write an expression whose value is true if and only if x is NOT a upper-case letter.

!(x>='A' && x<='Z')

20901: Assume that x is a char variable that has been declared and already given a value. Write an expression whose value is true if and only if x is an hexadecimal (Base 16) digit (0-9 plus A-F or a-f).

(( x>='0' && x<='9') || ( x>='a' && x<='f' ) || ( x>='A' && x<='F'))

20924: Assume that credits is an int variable whose value is 0 or positive. Write an expression whose value is “freshman” or “sophomore” or “junior” or “senior” based on the value of credits. In particular, if the value of credits is less than 30, the expression’s value is “freshman”; 30-59 would be a “sophomore”, 60-89 would be “junior” and 90 or more would be a “senior”.

(credits < 30) ? "freshman" : (credits >= 30 && credits < 60) ?"sophomore" : (credits >= 60 && credits < 90) ? "junior" : "senior"

20923: Assume that month is an int variable whose value is 1 or 2 or 3 or 5 … or 11 or 12. Write an expression whose value is “jan” or “feb” or “mar” or “apr” or “may” or “jun” or “jul” or “aug” or “sep” or “oct” or “nov” or “dec” based on the value of month. (So, if the value of month were 4, then the value of the expression would be “apr”.).

(month==1) ? "jan" : (month==2) ? "feb" : (month==3) ? "mar" : (month==4) ? "apr" : (month==5) ? "may" : (month==6) ? "jun" : (month==7) ? "jul" : (month==8) ? "aug" : (month==9) ? "sep" : (month==10) ? "oct" : (month==11) ? "nov" : "dec"

20623: Write a switch statement that texts the value of the char variable response and performs the following actions: if response is y, the message Your request is being processed is printed. if response is n, the message Thank you anyway for your consideration is printed. if response is h, the message Sorry no help is currently available is printed. for any other value of response, the message Invalid entry; pleas try again is printed.

switch ( response )


{


case 'y':


System.out.println( "Your request is being processed");


break;


case 'n':


System.out.println( "Thank you anyway for your consideration");


break;


case 'h':


System.out.println( "Sorry, no help is currently available");


break;


default:


System.out.println( "Invalid entry; please try again");


}

20926: HTTP is the protocol that governs communications between web servers and web clients (i.e. browsers). Part of the protocol includes a status code returned by the server to tell the browser the status of its most recent page request. Some of the codes and their meanings are listed below: 200, OK (fulfilled); 403, forbidden; 404, not found; 500, server error. Given an int variable status, write a switch statement that prints out, on a line by itself, the appropriate label from the above list based on status.

switch (status)


{


case 200:


System.out.println("OK (fulfilled)");


break;


case 403:


System.out.println("forbidden");


break;


case 404:


System.out.println("not found");


break;


case 500:


System.out.println("server error");


break;


}