Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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...

image text in transcribed

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

What causes variances in a budget at the end of a quater?

Answered: 1 week ago

Question

=+ f. instituting laws against driving while intoxicated

Answered: 1 week ago