Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?

image text in transcribed

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

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

More Books

Students also viewed these Databases questions

Question

=+(5.42) E[n \N2] = a, Var[n 'N.] - B - x2 +H-P n

Answered: 1 week ago