(Business: check ISBN-10) Rewrite the Programming Exercise 3.9 by entering the I
ID: 3792613 • Letter: #
Question
(Business: check ISBN-10) Rewrite the Programming Exercise 3.9 by entering the ISBN number as a string. (Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. (Check SSN) Write a program that prompts the user to enter a Social Security number in the format DDD-DD-DDDD, where D is a digit. Your program should check whether the input is valid. Here are sample runs: (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.Explanation / Answer
Hi, Please find my implementation.
import java.util.Scanner;
public class SubstringTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter string s1: ");
String s1 = sc.next();
System.out.print("Enter string s2: ");
String s2 = sc.next();
if(s1.contains(s2)){
System.out.println(s2+" is a substring of "+s1);
}else{
System.out.println(s2+" is not a substring of "+s1);
}
}
}
/*
Sample run:
Enter string s1: ABCD
Enter string s2: BC
BC is a substring of ABCD
Enter string s1: ABCD
Enter string s2: BDC
BDC is not a substring of ABCD
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.