Question: Topic: Mathematical Functions, Characters, and Strings Question: (4-22) (Check substring) Write a program that prompts the user to enter two strings and reports whether the
Topic: Mathematical Functions, Characters, and Strings
Question: (4-22) (Check substring) Write a program that prompts the user to enter two strings and reports whether the second string is a substring of the first string.
I've created the following code...

But I get the following error below. What do I need to enter to make it correct?

HasSubstring.java Java public class HasSubstring { public static void main(String[] args) { Scanner in = new Scanner (System.in); System.out.print("Enter string sl:"); String sl System.out.print("Enter string s2:"); String s2 = in.nextLine(); if(sl.contains(s2)){ System.out.println(s2 + } else { System.out.println(s2 + in.nextLine(); " is a substring of " + sl); " is not a substring of " + s 1); } COMPILER ERROR MESSAGES HasSubstring.java:3: error: cannot find symbol new Scanner (System.in); Scanner in = symbol: location: class HasSubstring HasSubstring.java:3: error: cannot find symbol class Scanner Scanner in = new Scanner (System.in); symbol: location: class HasSubstring class Scanner 2 errors 1 public class HasSubstring { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter string sl:"); String s1 = in.nextLine(); System.out.print("Enter string s2:"); String s2 = in.nextLine(); if(sl.contains (s2)){ System.out.println(s2 + } else { 2 3 4 + s1); is a substring of %3D 9. 10 is not a substring of + s1); 11 System.out.println(s2 + 12 } } 13 14 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
