AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Bluej exercise solutions chapter 45/2/2023 startsWith() tests if the string object starts with the string specified as its argument. How does endsWith() and startsWith() differ? Explain with an example.ĮndsWith() tests if the string object ends with the string specified as its argument. (ii) Convert a number stored in a string variable x to double data type. (i) Find and display the position of the last space in a string s. Write a statement each to perform the following task on a string: (ii) Check if the second character of a string str is in upper case.īoolean res = Character.isUpperCase(str.charAt(1)) (i) Extract the second last character of a word stored in the variable wd. Write a statement for each to perform the following task on a string: It returns the index within the string of the first occurrence of the specified character or -1 if the character is not present. State the purpose and return data type of the following String functions: Two exception handling blocks are try and catch. What is exception? Name two exception handling blocks.Īn exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. ![]() It extracts a part of the string as specified by its arguments and returns the extracted part as a new string. ![]() It returns a character from the string at the index specified as its argument Output of this code snippet will be HELLO. It checks if contents of two strings are same or not.The result is true if the contents are same otherwise it is false.Ĭonverts all characters of the String object to lower caseĬonverts all characters of the String object to upper case The result is a negative, positive or zero integer value depending on whether the String object precedes, follows or is equal to the String argument The output of this code snippet is false as s1 and s2 point to different String objects. It is used to check if two variables refer to the same object in memory It is used to check if the contents of two strings are same or not. Give the output of the following statements: X.substring(1,5) will return a substring of x starting at index 1 till index 4 (i.e. (S1 + " equalsIgnoreCase "+ S4 + " " + S1.equalsIgnoreCase(S4)) Ĭomputer World equals COMPUTER WORLD falseĬomputer World equals Computer world falseĬomputer World equals computer world falseĬomputer World equalsIgnoreCase computer world true X.length() will give the number of characters in string x which is 6. Str.indexOf('n') will return the first index of n in str which is 1. So, condition of ternary operator is false and false is assigned to boolean variable p. ![]() P = ("BLUEJ".length() > "bluej".length()) ? true: false īoth "BLUEJ" and "bluej" have the same length 5. So, 46 and 64 are added as numerical values and the result 110 is stored in int variable total. Integer.parseInt() method will convert the strings n1 and n2 to their corresponding numerical integers. Int total = Integer.parseInt(n1) + Integer.parseInt(n2) ![]() Next line prints "UnderstandingComputer Applications10" to the console. In the first line, + operator concatenates 1 and 0 to the end of "Computer Applications" so str becomes "Computer Applications10". String str = "Computer Applications" + 1 + 0
0 Comments
Read More
Leave a Reply. |