I am trying to get this to work on this website called myprogramminglab for college.
Instructions: 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.)
What MPL is going to test with and it has to be the exact format which I think I got:
Enter·first·string:Have·yourself·a·merry·little·Ch ristmas.↵
Enter·second·string:It's·beginning·to·look·a·lot·l ike·christmas.↵
Enter·starting·index·for·first·string:29·↵
Enter·starting·index·for·second·string:34·↵
Enter·number·of·characters·to·be·compared:9↵
true↵
My problem is that there is some errors in the prompts because it is not printing anything. Thanks!
Errors MPL gave me:
Failed Test Run #1
⇒ The contents of your standard output is incorrect.
⇒ There is an error in your prompts.
import java.util.Scanner; class compare { public static void main(String[] args) { int stind1,stind2,noc; String str1, str2, strtemp; Scanner scan = new Scanner(System.in); System.out.print("Enter First String:"); str1 = scan.nextLine(); System.out.print("Enter Second String:"); str2 = scan.nextLine(); System.out.print("Enter Starting Index of First string:"); stind1 = scan.nextInt(); System.out.print("Enter Starting Index of Second string:"); stind2 = scan.nextInt(); System.out.print("Enter number of characters:"); noc = scan.nextInt(); System.out.print("String 1 = " +str1+ "\n"); System.out.print("String 2 = " +str2+ "\n"); System.out.print("Starting index of first string " +stind1+ "\n"); System.out.print("Starting index of second string " +stind2+ "\n"); System.out.print("Number of characters to compare" +noc+ "\n"); System.out.println(str1.regionMatches(true,stind1,str2,stind2,noc)); } }