Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me out with this? You are given a program that receives four lines in the below format, and stores them in str1,

Can someone help me out with this?

You are given a program that receives four lines in the below format, and stores them in str1, str2, str3, and num1.

This is not a very long sentence. is long 4 

Expand this program to:

  • Write an if-elseif-else statement to
    • print this line only if num1 is higher than 0: "Num1 is higher than 0!"
    • print this line only if num1 is 0: "Num1 equals to 0!"
    • And otherwise, print: ""Num1 is lower than 0!"
  • Write another if-elseif-else statement to
    • if the length of str1 or str2 is lower than 1, print: "Error! Analysis is not possible!"
    • otherwise, if the length of the sentence is lower than 5 and str1 contains str2, print:"Barely a sentence but had the word!"
    • otherwise, if the length of the sentence is lower than 5 and str1 DOES NOT contain str2, print:"Barely a sentence and DID NOT have the word!"
    • otherwise, if the length of the sentence is between 5 (inclusive) and 20 (exclusive) and str1 contains str2, print:"A sentence and had the word!"
    • otherwise, if the length of the sentence is between 5 (inclusive) and 20 (exclusive) and str1 DOES NOT contain str2, print:"A sentence and DID NOT have the word!"
    • In any other case, prints: "Sentence is too long for analysis."
  • Prints the first and last character of str1 in the below format:
[first character][last character] 
  • Search str1 for str2,

    • do nothing if it couldn't find it.
    • and print this line to the console if it could:"Found it!"
  • Compare str2 and str3 and

    • print str2 if str2 is larger than str3
    • print str3 if str2 is smaller than str3
    • print this line if str2 equals str1: "They are equal!"
  • Find the str2 in str1, and

    • if it could be found, print two separate strings, one string from the beginning of str1 to right before str2, and another one from the end of str2 until the end of the string.
    • Otherwise, do nothing.
    • For example, if the input is:
This is not a very long sentence. er long 4 

The output will be:

This is not a v y long sentence. 

Below is the list of methods that you might need

  • str1.equals(str2)
  • str1.contains(str2)
  • str1.startsWith(str2) / str1.endsWith(str2)
  • str1.compareTo(str2)
  • str1.equalsIgnoreCase(str2)
  • str1.compareToIgnoreCase(str2)
  • str1.charAt(int);
  • str1.length()
  • str1.indexOf(char/String)
  • str1.replace(str2,str3)
  • str1.substring(firstIndex,secondIndex+1)
  • str1.concat(str2)

import java.util.Scanner;

public class Main { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String str1 = scnr.nextLine(); String str2 = scnr.nextLine(); String str3 = scnr.nextLine(); int num1 = scnr.nextInt();

// Write your code below. } }

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

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

Students also viewed these Databases questions

Question

Enhance the basic quality of your voice.

Answered: 1 week ago

Question

Describe the features of and process used by a writing team.

Answered: 1 week ago