Suppose s1, s2, and s3 are three strings, given as follows:
String s1 = "Welcome to Java";
String s2 = "
String s3 = "Welcome to Java";
What are the results of the following expressions?
(a) s 1 == s2
(b) s2 == s3
(c) s1 .equals(s2)
(d) s2.equals(s3)
(e) s1 .compareTo(s2)
(f) s2.compareTo(s3)
(g) s2. compareTo(s2)
(h) s1. charAt (0)
(i) s1. indexOf (' j ')
(j) s1.indexOf("to")
(k) s1. last IndexOf ('a')
(1) s1 .1 astlndexOf ("o" , 15)
(m) s1.1ength()
(n) s1 .substring(5)
(o) s1 .substring(5, 11)
(p) s1.startsWith("Wel")
(q) s1.endsWith("Java")
(r) s1 .toLowerCase()
(s) s1 .toUpperCase()
(t) s1 .concat (s2)
(u) s1.contain(s2)
(v) "\t Wel \t".trim()
Trending nowThis is a popular solution!
Chapter 4 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Using MIS (10th Edition)
Programming in C
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Python (4th Edition)
Artificial Intelligence: A Modern Approach
- Write in Java Prompt the user for a string that contains two strings separated by a comma. Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allenarrow_forwardin Java, Write a program that reads student scores, gets the best score, and then assigns grades based on the following scheme:• Grade is A if score is ≥ best − 10• Grade is B if score is ≥ best − 20;• Grade is C if score is ≥ best − 30;• Grade is D if score is ≥ best − 40;• Grade is F otherwise.The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. Here is a sample run: number of students: 4 scores are: 40.0, 55.0, 70.0, 58.0 Student 0 score is 40.0 and grade is C Student 1 score is 55.0 and grade is B Student 2 score is 70.0 and grade is A Student 3 score is 58.0 and grade is Barrow_forwardWRITE IN JAVA USING JOptionPane.showInputDialog Write a program that reads a sentence as input and converts each word to “Pig Latin”. In one version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end of the word, and then appending “ay” to the word. Here is an Example: English: I SLEPT MOST OF THE NIGHT Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY EXAMPLE:arrow_forward
- in java First, read the first floating-point number from input. Then, read the remaining floating-point numbers while the floating-point numbers are in the range -20.0 to 20.0, both exclusive. Output the total number of floating-point numbers read in the given range. End with a newline. Ex: If the input is -14.0 -26.5 -13.0 -17.5 -18.0 -16.5 -12.5 -15.0, then the output is: Number of floating-point numbers read: 1 Note: -20.0 and 20.0 are not in the given range. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import java.util.Scanner; public class CountRead { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); doubleinputData; intcountRead; countRead=0; /* Your code goes here */ } }arrow_forward3. Write a Java program that takes the user to provide a single character from the alphabet. Print Vowel or Consonant, depending on the user input. If the user input is not a letter (between a and z or A and Z), or is a string of length > 1, print an error message.4. Write a program in Java to input 5 numbers from keyboard and find their sum and average.arrow_forwardIN JAVA Trace the evaluation of the expressions and give the resulting values. (Make sure to give a value of the appropriate type, such as including a .0 at the end of a double result. If the result is a String, enclose the String in double quotes.) 8 / 5 + 13 % 2 / 3.0 10 / 4 / 2 (12 + (8 * -1) - 3) / 4 * 2 5 * 7 % 4 + “Hi” + 4 - 3arrow_forward
- In Java write a program to read Input a string and find number of uppercase alphabets in it.arrow_forwardTHIS IS IN JAVA. A restaurant serves breakfast before 11 am, after which they serve lunch. Which expression for XXX outputs the correct string for any time? Variable time ranges from 0 to 23 (e.g., 13 means 1 pm). mealString=XXX;// Output mealString A. (time > 11) ? "Breakfast" : "Lunch" B. (time == 11) ? "Breakfast" : "Lunch" C. (time < 11) ? "Breakfast" : "Lunch" D. (time != 11) ? "Breakfast" : "Lunch"arrow_forwardThis is meant to be written in JAVA So far we've learned variables, branches, loops, and just started learning some array. This is the assignment: Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "!" to the end of the input string. i becomes 1 a becomes @ m becomes M B becomes 8 s becomes $ Ex: If the input is: mypassword the output is: Myp@$$word! Please show the end result and explain why you added what you added. This is what I have so far: import java.util.Scanner; public class LabProgram {public static void main(String[] args) {}}arrow_forward
- When we say arithmetic expression, we mean a kind of expression you can type in a very basic desk calculator. That is, neither variables nor brackets are allowed. It contains only numbers and four arithmetic operators, +, -, *, and /. The following are some examples of arithmetic expression: Any number string with or without signs - e.g. 3, -1, +10, 3.14, -0.70 and 099. Number strings mixed with arithmetic operators - e.g. 3+5, -1+2*3, 7/10-0.7, and -1.4-+8.2. An example of FA diagram for recognising a non-negative integer is given below. You may use it as a start point. You need to add a few more states and transitions to handle numbers with decimal point and signs (e.g. -5, +2, 0.21, -32.6, +99.05, but not the form 1.0E-3). Most importantly, you also need to add a few more things to deal with the arithmetic operators +, -, *, /.arrow_forwardIN JAVA. Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 77 the output is: 77 Ex: If the input is: 15 or any number not between 20 and 98 (inclusive), the output is: Input must be 20-98arrow_forwardWrite a Program that take 2 string from user and print the whole with greetings. Those 2 strings are first name and last name in javaarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education