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, Student Value Edition (11th Edition)
- Determine whether these statements are true or false. Enter T or F. (a) ØE{Ø} (b) { Ø}E{Ø} (c) ØC{Ø} (d) Ø E{0}arrow_forward“As one variable goes up, the other variable goes down” is a description of:arrow_forwardThe following statement should determine if x is not greater than 20. What is wrong with it?arrow_forward
- 1: If the variable divisor is not zero, divide the variable dividend by the divisor, and store theresult in quotient. If divisor is zero, assign it to quotient. Then print all the variables. [ Assumethat divisor and dividend are integers and quotient is a double ]arrow_forwardQ16: Rewrite the equivalent statements for the following examples, and find it results. Assume: X=2, Y=3, Z-4, V=12 , C=8. (X+=5, Y--8, Z*=5, V/-4, C %=3) Q17: Given that A and B are real variables with values 1.5, and 2.5 respectively, and C is integer variable with value 3, evaluate the following: NOT (A< 0) AND (B/C <= 0).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_forward
- Show the value of x after each of the statements is performed: x = fabs(0.0);arrow_forwardLet H be "The weather is hot" and D be " The weather is dry ", then the statement "it is false that, the weather is not hot or dry " can be written in logical notation as Select one: -(-H) v D -(Hv -D) -(-H v D) -(H v D)arrow_forwardLet p = “It is raining” q = “I am wearing my rubbers" s = “I am carrying my umbrella”. Express each of the following statements in symbols: (a) “Either it is not raining, or I am wearing my rubbers and I am carrying my umbrella.” (b) “It is raining, still I am neither wearing my rubbers nor carrying my umbrella.”arrow_forward
- 3. 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_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_forwardDeclare int variables x and y. Initialize x to 25 and y to 18.arrow_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,