Question: Hello I need help on this, please write the code for this java program: Write a Java program named Contains that asks the user to
Hello I need help on this, please write the code for this java program:
Write a Java program named Contains that asks the user to enter two strings and displays the position where the second string occurs within the first. Note it is possible that the second string will not occur in the first. The Java String method you should use will handle this situation your output to the user should be the value returned by this method with an explanation of the specific value that indicates the second string was not found in the first. Please don't use if statements or any loops and keep it all in the main method.
Thanks
This is what I have so far:
import java.util.Scanner;
public class Contains { public static void main (String args[]) { Scanner in = new Scanner(System.in); System.out.println("Please enter a word or characters."); String input1 = in.nextLine(); System.out.println("Please enter another word or characters."); String input2 = in.nextLine(); System.out.println("Your first word is " + input1 + " and your second word is " + input2 + "."); int intPosOne = input1.indexOf(input1); System.out.println(intPosOne); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
