Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming language is JAVA: Write the expressions specified below. Note: these

ID: 3830760 • Letter: P

Question

Programming language is JAVA:

Write the expressions specified below. Note: these are not statements, so there is no semicolon!


a. evaluates to true just when n is between 1 and 10 (inclusive). _______________________


b. evaluates to true just when String s is equal to String t. ______________________


c. evaluates to true just when String s is the empty string. _____________________________


d. evaluates to the next to last element of array nums. (Assume nums.length > 1.) ________________________________


e. evaluates to z minus twice the sum of x and y. _________________________________


f. evaluates to a random integer from 1 to 10 (Use (int) and Math.random() ) ___________________________________


g. evaluates to the maximum of x and y. _________________________


h. evaluates to the integer value of the String s. ______________________________


i. evaluates to true if char c is a lowercase or uppercase letter and false otherwise. _________________________


j. evaluates to false if int x is a multiple of three and true otherwise. ___________________________________

Explanation / Answer

Answer in Bold.

a. evaluates to true just when n is between 1 and 10 (inclusive). n >= 1 && n <= 10

b. evaluates to true just when String s is equal to String t. s.equals(t)


c. evaluates to true just when String s is the empty string. s.isEmpty()


d. evaluates to the next to last element of array nums. (Assume nums.length > 1.) ________________________________num[nums.length] (this is not allowed though)


e. evaluates to z minus twice the sum of x and y. _________________________________z - 2*(x+y);


f. evaluates to a random integer from 1 to 10 (Use (int) and Math.random() ) ___________________________________Math.random (int)(Math.random()*10);


g. evaluates to the maximum of x and y. _________________________ x> y ? x : y


h. evaluates to the integer value of the String s. ______________________________Integer.parseInt(s);


i. evaluates to true if char c is a lowercase or uppercase letter and false otherwise. _________________________Character.isAlphabetic(c)


j. evaluates to false if int x is a multiple of three and true otherwise. ___________________________________ (x % 3 != 0)