Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

String color = \"bluegrey\" ; int index = color.indexOf ( \'e\' ) ; Output: 3 (3

ID: 3625723 • Letter: S

Question

String color = "bluegrey";
int index = color.indexOf('e');

Output: 3 (3 characters of the string bluegrey before the match of letter "e" in the string.

Output:
** Should not matter if first or second string is lowercase or uppercase. Program should accept either as long as its the same string or word. If possible.

Must ask user to enter first string in GUI: JOptionPane.showInputDialog()

Must ask user to enter second string in GUI: same as above

Displays message "first string" is a substring of "second string" at position x (counts #characters in second string before the match).
Use GUI to display message or result: JoptionPane.showMessageDialog()

Explanation / Answer

import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String a,b; a=JOptionPane.showInputDialog("Enter 1st String"); b=JOptionPane.showInputDialog("Enter 2nd String"); int index1 = a.indexOf(b); if (index1 != -1) System.out.println("The string"+a+" contains the substring " + b+"at position "+index1); else System.out.println("The string does not contain the substring " + b); } }