Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will write a program to perform some String operations. Read the input from the scanner Declare st1 and st2 as type String. Declare ch1
You will write a program to perform some String operations. Read the input from the scanner Declare st1 and st2 as type String. Declare ch1 and ch2 as char. Compare the strings and display, as appropriate o Which string is longer The 5 character of st1, or a message if the string has less than 5 characters Which word comes before in an alphanumeric comparison o Display if ch1 appears in st1 or not o The last position of ch2 in st2 (or - 1 if not in the string) Use printf for all of your output. Use appropriate format specifiers like %5, %d, %c, etc. Name your class program "String Operations" and submit your .java file in Canvas Sample output: Example 1: Enter two words and two characters: hello world a w Your words are: hello and world. And your characters are a and w. world is the same length as hello. The fifth character in hello is o. hello comes before world. a is not found in hello. The last position of w in world is index Example 2: Enter two words and two characters: hello Hello wy Your words are: hello and Hello. And your characters are w and y. Hello is the same length as hello. The fifth character in hello is o. Hello comes before hello. w is not found in hello. The last position of y in Hello is index -1 Example 3: Enter two words and two characters: java 823 w 2 Your words are: java and 823. And your characters are w and 2. java is longer than 823. java is less than five characters long. 823 comes before java. w is not found in java. The last position of 2 in 823 is index 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started