Write a Java class named StringProcess that prompts the user to enter two non-empty strings and report the followings: 1) The length of the two strings 2) The ASCII value of the first letter in the first string 3) The ASCII value of the last letter in the second string 4) Whether the second string is a substring of the first string.
Outputs: Your output should look similar as follows.
Please enter the first string: Carrot
Please enter the second string: Car
The ASCII value of the first letter in string carrot is: 67
The ASCII value of the last letter in string Car is: 114
The second string Car is a substring of the first string Carrot.
import java.util.Scanner; public class StringProcess { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter the first string: "); String s1 = in.nextLine(); System.out.print("Please enter the second string: "); String s2 = in.nextLine(); System.out.println("The ASCII value of the first letter in string " + s1 + " is: " + (int) s1.charAt(0)); System.out.println("The ASCII value of the last letter in string " + s2 + " is: " + (int) s2.charAt(s2.length() - 1)); if (s1.contains(s2)) { System.out.println("The second string " + s2 + " is a substring of the first string " + s1 + "."); } else { System.out.println("The second string " + s2 + " is not a substring of the first string " + s1 + "."); } } }
Write a Java class named StringProcess that prompts the user to enter two non-empty strings and...
Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...
Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to enter an item’s name for each position in the array. The program then prints uses a loop to output the array. Example 1: Banana 2: Orange 3: Milk 4: Carrot 5: Chips Banana, Orange, Milk, Carrot, Chips Problem 2: Print Characters in String Array Declare a string array of size 5. Prompt the user enters five strings that are stored in the array....
Write Java code that prompts the user to enter his or her full name, then prints the name in reverse order (i.e., last name, first name). Read an entire line as a single string. Here is an example dialogue with the user: Please enter your full name: Sammy Jankis Your name in reverse order is Jankis, Sammy
write a java program that prompts a user to enter two different numbers, divide the first number by second and prints the result
Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...
Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...
Write a program named "VegetablePricer" which prompts the user for a vegetable from the pricing table shown below. The program will then display the cost per pound for that vegetable, again using the table provided. Your program must use a switch statement to process the input value and display the desired output. Be sure to provide a default case in your switch statement which handles unrecognized input. Use named constants for all constant strings (e.g. prompts and vegetable names) and...
In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....
Write java program that prompts the user to enter integers from the keyboard one at a time. Program stops reading integers once the user enters the same value three times consecutively. Program then outputs "Same entered 3 in a row. "
In Java - Write a program that prompts the user to enter two integers and displays their sum. If the input is incorrect, prompt the user again. This means that you will have a try-catch inside a loop.