Question

In: Computer Science

In Java please. Prompt the user for two string inputs. Perform the following actions on these...

In Java please.

  • Prompt the user for two string inputs.
  • Perform the following actions on these inputs, and print the result of each action:

Part I:

  1. Concatenate the two strings into one.
  2. Compare the two strings and check whether they are the same (ignore the case).
    Look up the method equalsIgnoreCase() from Java API
  3. Convert all the characters in a string to uppercase
    Look up the method toUpperCase() from Java API

Part II:

  1. Replace all the 'd' characters with ‘e' characters in both strings
    Look up the method replace() from Java API
  2. Prompt the user for a third string and check whether any of the previous two strings ends with the third string as their substring, i.e., the word "nice" contains the substring "ice"

Solutions

Expert Solution

Main.java

import java.util.*;
import java.lang.*;
public class Main
{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("enter any two strings");
        String s1 = sc.nextLine();
        String s2 = sc.nextLine();
        String con = s1+s2;
        System.out.println("concatenated string is: "+ con);
        if(s1.equalsIgnoreCase(s2))
        {
            System.out.println("Both strings are equal");
        }
        else{
            System.out.println("Both strings are equal");
        }
        System.out.println("String when converted to upper case:");
        System.out.println(s1.toUpperCase());
        System.out.println(s2.toUpperCase());
        System.out.println("after replacing d with e");
        System.out.println(s1.replace('d','e'));
        System.out.println(s2.replace('d','e'));
        System.out.println("enter third string");
        String s3 = sc.nextLine();
        if(s1.endsWith(s3))
        {
            System.out.println(s1+"ends with "+s3);
        }
       else{
            System.out.println(s1+" doesnt ends with "+s3);
        }
       if(s2.endsWith(s3))
       {
               System.out.println(s2+"ends with "+s3);
        }
       else{
            System.out.println(s2+"doesnt ends with "+s3);
        }
        
    }
}

PLEASE DO COMMENT IN CASE OF ANY DOUBTS.


Related Solutions

6.6 Parsing strings (Java) (1) Prompt the user for a string that contains two strings separated...
6.6 Parsing strings (Java) (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)...
(1) Prompt the user for a string that contains two strings separated by a comma.
(In C)(1) Prompt the user for a string that contains two strings separated by a comma. Examples of strings that can be accepted:Jill, AllenJill , AllenJill,AllenEx:Enter input string: Jill, Allen(2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. Ex:Enter input string: Jill Allen Error: No comma in string. Enter input string: Jill, Allen(3) Extract the two words from the input string and remove any spaces. Store...
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
use c++ (1) Prompt the user for a string that contains two strings separated by a...
use c++ (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Print an error message if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts) Ex:...
(1) Prompt the user for a string that contains two strings separated by a comma. (1...
(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Print an error message if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts) Ex: Enter input...
8.30 LAB*: Program: Authoring assistant. PYTHON PLEASE!! (1) Prompt the user to enter a string of...
8.30 LAB*: Program: Authoring assistant. PYTHON PLEASE!! (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be...
Write a program to perform the following actions: the language is Java – Open an output...
Write a program to perform the following actions: the language is Java – Open an output file named “Assign14Numbers.txt” – Using a do-while loop, prompt the user for and input a count of the number of random integers to produce, make sure the value is between 35 and 150, inclusive. – After obtaining a good count, use a for-loop to generate the random integers in the range 0 ... 99, inclusive, and output each to the file as it is...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT