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: Brief Version (11th Global Edition)
- The following statement should determine if x is not greater than 20. What is wrong with it?arrow_forward: Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), I (OR), and / (XOR), and a desired boolean result value result, create a function that counts the number of ways the expression may be parenthesized such that it evaluates to result. The expression should be completely parenthesized (for example, (0) A(1)) but not excessively (for example, (((0)) / (1))).EXAMPLE \scountEval("l/01011", false) yields 2 counts."0&0&0&1All0", true) = 10arrow_forwardPlease answer item number 3. (pyhthon programming)arrow_forward
- :Q3: Answer the following Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 5 and the value of the variable limit is -1. Give your answer as one of the values true or false. a. (count = ((0 c. (limit/count) > 7) || (limit < 20) IMI r263 LAlas Google la e 1ajall lals Juayl paearrow_forward3. The formula for determining compound interest is: A represents the amount to earn; P is the principle that is initially invested; r is the interest rate earned; n is the number of times the interest is compounded; and t is the number of time periods for the investment. Write a program that prompts the user to enter P, r, n and t. The program should output the amount earned on the investment. 4. Look up the Pythagorean theorem if you are not already familiar with it. Use the following formula to solve for c in the formula: c = √a2 + b2. Use the proper functions from the cmath header file. Be sure to output the result.larrow_forwardShow the value of x after each of the statements is performed: x = fabs(-6.4);arrow_forward
- A variable x is assigned a NULL value. The return value from the function is.null(x) will be a. TRUE b. "Number" c. NULL d. "Character"arrow_forwardCan only use boolean opearators and numerical comparisons.arrow_forwardWrite a Boolean expression that is true if and only if a student is a senior who is majoring in either Information Technology or Computer Science and has a GPA of at least 3.5 but not higher than 3.85. Assume that the student’s year in school is stored in the variable year, the student’s major is stored in the variable major, and the student's GPA is stored in the variable gpa. Use parentheses to indicate clearly the order in which the operations should be evaluated.arrow_forward
- The following statement is valid. int x, X; True Falsearrow_forwardWhat 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_forward5. (Algebra: solve 2 X 2 linear equations) You can use Cramer's rule to solve the following 2 X 2 system of linear equation: ax + by = e cx + dy = f ● x = ed - bf bc ad y = af - ec ad bc - Write a program that prompts the user to enter a, b, c, d, e, and f and display the result. If ad- bc is 0, report that The equation has no solution. Enter a, b, c, d, e, f: 9.0, 4.0, 3.0, -5.0, -6.0, -21.0 Enter x is -2.0 and y is 3.0 Enter a, b, c, d, e, f: 1.0, 2.0, 2.0, 4.0, 4.0, 5.0 Enter The equation has no solutionarrow_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,