Concept explainers
Let s1 be " Welcome " and s2 be " welcome ". Write the code for the following statements:
(a) Check whether s1 is equal to s2 and assign the result to a Boolean variable isEqual.
(b) Check whether s1 is equal to s2, ignoring case, and assign the result to a Boolean variable isEqual.
(c) Compare s1 with s2 and assign the result to an int variable x.
(d) Compare s1 with s2, ignoring case, and assign the result to an int variable x.
(e) Check whether s1 has the prefix AAA and assign the result to a Boolean variable b.
(f) Check whether s1 has the suffix AAA and assign the result to a Boolean variable b.
(g) Assign the length of s1 to an int variable x.
(h) Assign the first character of s1 to a char variable x.
(i) Create a new string s3 that combines s1 with s2.
(j) Create a substring of s1 starting from index 1.
(k) Create a substring of s1 from index 1 to index 4.
(l) Create a new string s3 that converts s1 to lowercase.
(m) Create a new string s3 that converts s1 to uppercase.
(n) Create a new string s3 that trims whitespaces on both ends of s1 .
(o) Assign the index of the first occurrence of the character e in s1 to an int variable x.
(p) Assign the index of the last occurrence of the string abc in s1 to an int variable x.
Trending nowThis is a popular solution!
Chapter 4 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
- 7. Let the statements A, B be given by A: not(p or q), B: (not p) or q. Let T = true, F = false. If p = T and q = F, then O A = T, B = T O A = F, B = T O A = F, B = F O A= T, B = Farrow_forwardAssume that isIsosceles is a boolean variable, and that the variables isoCount,triangleCount, and polygonCount have all been initialized. Write a statement that adds 1 to each of these count variables (isoCount,triangleCount, and polygonCount)if isIsosceles is true.arrow_forward1. Supposed a ball is thrown straight up in the air with an initial velocity of 50 feet per second and an initial height of 5 feet. How high will the ball be after 3 seconds? Note: The height after t seconds is given by the expression - 16t+vot+ho, where ve is the initial velocity and he is the initial height.arrow_forward
- A student makes the following argument. if I receive a good grade, the instructor teaches well. I didn't receive a good grade. Therefore, the instructor didn't teach well. is the student's argument valid? Let A be the statement, "I receive a good grade" and B be the statement, " the instructor teaches well." Then, rewrite the above paragraph using A and B.arrow_forwardTranslate the statement into equation: When three is multiplied by one less than a number x, the result is 10 less than 5 times the number x.arrow_forward3. Let K(x) be the statement “x has a pet koala,” let G(x) be the statement “x has a gazelle," let U(x) be the statement "x has a unicorn," and let F(x) be the statement "x has a farm." Express each of these statements in terms of K(x), G(x), U(x), F(x), quantifiers, and logical connectives. Let the domain consist of all people. (a) Everyone owns a gazelle or a unicorn. (b) Any person who does not own a farm cannot own a koala, gazelle, or unicorn. (c) No one owns a gazelle, but everyone owns a koala. (d) Some people own both a unicorn and a farm, but not all people own both a koala and a gazelle. (e) Each type of animal (koala, gazelle, unicorn) is owned by at least one person.arrow_forward
- Write a Boolean expression that is true if and only if a student is a senior who is majoring in either physics or chemistry. Assume that the student’s year in school is stored in the variable year and the student’s major is stored in the variable major. Use parentheses to indicate clearly the order in which the operations should be evaluated.arrow_forward28. If originally x=4, what is the value of x after the evaluation of the expression: x+=4arrow_forwardPart I: Proving that an argument is valid using rules of inference 1. Write each of the following arguments in argument form. Then, use the rules of inference to show that each argument is valid. a. Let p be the proposition "/ attend the lecture," q be “I watch the lecture recording." and r be "I do well on the quiz." If I attend the lecture, then I do well on the quiz. I attend the lecture or watch the lecture recording. I did not watch the lecture recording. Therefore, I did well on the quiz. b. Let P(x) be "x attended the lecture," Q(x) be "x submitted the homework assignment," and R(x) be "x passed the exam," where the domain consists of all students in this class. Every student in this class who did not attend the lecture or did not submit the homework assignment did not pass the exam. Bob, who is a student in this class, passed the exam. Therefore, Bob attended the lecture. c. Let P(x) be "x has taken CS 109," Q(x) be “x has taken CS 111," and R(x) be "x has permission from the…arrow_forward
- What is the value of each of the following Boolean expressions? 54 3=3 2+45 6==7 2+4=6 3+4==4+3 1!=2 2!=2 5==72 3+9=0arrow_forwardC - Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to pointsDistance. The calculation is:arrow_forwardGiven a and b are int variables and c is a double variable. The initial value for a, b, and c are 8, 4, and 2.5. Show the working steps and result for the following expression:(i) a + b++ - carrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,