Question: Java Programming Topic: Conditionals and Strings Exercise: Write a program that prompts the user to enter two strings and reports whether the second string is

Java Programming

Topic: Conditionals and Strings

Exercise: 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 compiled the following code...

import java.util.Scanner;

class Exercise_04_22 { static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter string s1: "); String s1 = in.nextLine(); System.out.print("Enter string s2: "); String s2 = in.nextLine(); if (s1.indexOf(s2) != -1) { System.out.printf("%s is a substring of %s%n", s2, s1); } else{ System.out.printf("%s is not a substring of %s%n", s2, s1); } } }

But it gives me the following error in MyProgrammingLab. What do I need to do or change to make this correct?

Java Programming Topic: Conditionals and Strings Exercise: Write a program that prompts

Print Content Results Support CODELAB ANALYSIS: LOGICAL ERROR(S) Problems Detected: = The contents of your standard output is incorrect. Given the following was entered from the keyboard: apple Apple you displayed: instead of: Enter string s1: Enter string s2: Apple is not a substring of apple Failed 4 out of 4 test runs. IDDO + Failed Test Run #1 - The contents of your standard output is incorrect. There is an error in your prompts. Standard Output - W (Hide Invisibles Expected Result: Enter stringsli Enter.string.s2 pre is.a.substring of precocious Your Code's Actual Result

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!