Suppose s1, s2, s3, and s4 are four strings, given as follows:
String s1 = “Welcome to Java”;
String s2 = s1;
String s3 = new String(“We1come to Java”);
String s4 = “Welcome to Java”;
What are the results of the following expressions?
a. s1 == s2
b. s1 == s3
c. s1 == s4
d. s1.equals(s3)
e. s1.equals(s4)
f. “Welcome to Java”.replace(“Java”, “HTML”)
g. s1.replace(‘o’, ‘T’)
h. s1.replaceAll(“o”, “T”)
i. s1.rep1aceFirst(“o”, “T”)
j. s1.toCharArray()
Trending nowThis is a popular solution!
Chapter 10 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Using MIS (10th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Starting Out with C++: Early Objects
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- Java Program - Functions With Parameters and No Return Values Create a function named palindrome that asks the user a string input if called. If the string is a palindrome, print “{input} is a palindrome!”, otherwise print “{input} is not a palindrome!”. In the main function, call the palindrome function. Input 1. One line containing a single string Output Enter a string: racecar racecar is a palindrome!arrow_forwardJava with out string formarrow_forwardin java plarrow_forward
- Suppose that you declare two String objects as: String word1 = new String("Computer"); String word2 = new String("Science"); Write an if statement that checks to see if the two strings are equal.arrow_forwardDescriptionA researcher is analyzing DNA. A DNA can be represented as a string composed of the characters A, G, C, or T.One day, researchers found a strange DNA, which is Smooth Repeated DNA. The DNA is represented by a string that has infinite length. The string has a repeating pattern, i.e. the DNA string 0 is repeated an infinite number of times. For example, if0 = "????", then = "???????????? . . . ".According to researchers, a DNA is said to be special if it contains substrings . Determine whetheris a substring of . Squad FormatA line containing the two strings 0 and . Output FormatA line that determines whether it is a substring of . Issue “YES” ifis a substring of . Output “NO” otherwise. Example Input and Output Input Example Example Output AGCT GC YES AGCT TA YES AGCT GT No AGCT TAGCTAGCT YES AGGACCTA CTAA YES Explanation ExampleIn the first to fourth test case examples, is worth "???????????? . . . ". The part in bold is one of the…arrow_forwardIn java please help with the following: Given a string that contains space separated words, write an application that displays the words in ascending order (If two words are the same, display only one). You need to use the right data structure for storing the words. For example, for input:String input="apple banana apple orange blueberry"; The program will print out: apple banana blueberry orangearrow_forward
- Write a program that prompts the user for a sentence and display in new words. Your program should behave as follow: 1. Display a welcome message. 2. Ask the user for prompting a string with 3 words and 1 punctuation without any spaces. 3. Display the length of the string sentence. 4. Separate the words in the phrase a. Prompt user for the length of each word b. Display the complete sentence with the punctuation in the end. 5. Display a farewell message, so that the user knows that the program has terminated normally. Restrictions: No looping statements allowed (or needed). This question requires the use of the functions: length(), substr() to generate the complete sentence. Following are the sample screen shots to illustrate the expected behavior of your program. User input at the keyboard is marked with a red circle. Your program should work with any sentence with 3 words entered by the user. Assume a perfect user who will always enter correct info. Note: Your program must display…arrow_forwardpython3 programarrow_forwardthe function returns the result as a string if the expression is legal. the expression returns an empty string and then put the function public class Ez1MathEval {public String heavywtEval (String exprn) {return ""}}arrow_forward
- Java Programming: Question 12 Not sure how to do this question. Help of any input and output would be appreciated.arrow_forwardHi, I need assistance please with my java code to implement the below problem. The Java program uses Genetic Algorithms to recognize a string. Below is the code. Im missing some functionalities that enables the program to work successfully. Thank you The program is intended to work as follows: The user can input the string to guess. The user can enter the number or organisms in the population. The user can enter the number of generations to create. The user can enter the mutation probability. The user can observe the progress of the GA, for example print the best answer in every 10th generation. After the prescribed number of generations, the program should print best/final answer. The program should “guesses” the string “We the people of the United States in order to perform a perfect union” and print result import java.util.Scanner;public class GATest { public static void main(String[] arg) { boolean repeat = true; while(repeat) { Scanner…arrow_forwardTake a string trom the user, print a new string made of 3 copies of the first 2 chars of the original string. Preferred Programming language: Javal Perlarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT