1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
PilotLPTM [1.2K]
3 years ago
11

We define the following terms:

Computers and Technology
1 answer:
Degger [83]3 years ago
3 0

Answer:

Here is the JAVA program:

import java.util.*;  

public class Solution {    // class name

   public static String getSmallestAndLargest(String s, int k) {   //method that takes a string s and and integer k and returns lexicographically smallest and largest substrings

       String smallest = "";   //stores the smallest substring

       String largest = "";   //stores the largest substring

       smallest = largest = s.substring(0, k);  //sets the smallest and largest to substring from 0-th start index and k-th end index of string s

       for(int i = 0;i<=s.length()-k;i++){  //iterates through the string s till length()-k

            String subString = s.substring(i,i+k);  //stores the substring of string s from ith index to i+k th index

            if(i == 0){ //if i is equal to 0

                smallest = subString;              }  //assigns subString to smallest

            if(subString.compareTo(largest)>0){ //checks if the subString is lexicographically greater than largest

                largest = subString;  //sets subString to largest

            }else if(subString.compareTo(smallest)<0)  //checks if the subString is lexicographically less than smallest

                smallest = subString;       }       //sets subString to smallest

       return smallest + "\n" + largest;     }  //returns the lexicographically smallest and largest substrings

   public static void main(String[] args) {  //start of main method

       Scanner scan = new Scanner(System.in);  //creates Scanner object

       String s = scan.next();  //scans and reads input string from user

       int k = scan.nextInt();  //scans and reads integer k from user

       scan.close();  

       System.out.println(getSmallestAndLargest(s, k));      }  }  //calls method by passing string s and integer k to it to display lexicographically smallest and lexicographically largest substring

Explanation:

The program takes a string s and an integer k and passes them to function getSmallestAndLargest that returns the lexicographically smallest and lexicographically largest substring. The method works as follows:

Lets say s = helloworld and k = 3

       smallest = largest = s.substring(0, k);

s.substring(0, k);  is returns the substring from 0th index to k-th index so it gives substring hel

       for(int i = 0;i<=s.length()-k;i++) This loop iterates through the string s till s.length()-k times

s.length()-k is equal to 7 in this example

At first iteration:

i = 0

i<=s.length()-k is true  so program enters the body of loop

String subString = s.substring(i,i+k); this becomes:

subString = s.substring(0,3);

subString = "hel"

if(i == 0) this is true so:

smallest = subString;

smallest = "hel"

At second iteration:

i = 1

i<=s.length()-k is true  so program enters the body of loop

String subString = s.substring(i,i+k); this becomes:

subString = s.substring(1,4);

subString = "ell"

if(subString.compareTo(smallest)<0) this condition is true because the subString ell is compared to smallest hel and it is lexographically less than smallest so :

smallest = subString;

smallest = "ell"

So at each iteration 3 characters of string s are taken and if and else if condition checks if these characters are lexicographically equal, smaller or larger and the values of largest and smallest change accordingly

After the loop ends the statement return smallest + "\n" + largest; executes which returns the smallest and largest substrings. So the output of the entire program with given example is:

ell                                                                                                                                           wor

Here ell is the lexicographically  smallest substring and wor is lexicographically  largest substring in the string helloworld

The screenshot of the program along with its output is attached.

You might be interested in
Which three are true about converting tabular, summary, or matrix report to a joined report?Choose 3 answersA.Report formula fie
Maurinko [17]

Answer:

Option B, C, and D is the correct options to the following question.

Explanation:

Because the joined report is that type of report which consists of the different standards of data or custom method types of report, in which user can add new accounts to the joined account or report. The joined reports do not support the display filter to the rows and it also not support the bucket field and the cross filters. So, that's why the following option is true.

3 0
4 years ago
And, Or, Not are examples of:
yanalaym [24]
Boolean operators it is
all the best
5 0
3 years ago
Which statement is true with regard to project scheduling?
Anit [1.1K]

Answer:

B: plant based processes use an iterative approach for scheduling each phase of the project

8 0
3 years ago
A website theme has most to do with a site's:
krek1111 [17]
Your answer is overall design
6 0
3 years ago
Read 2 more answers
Explain the three major Subassembly<br>of a computer Keyboard​
mixas84 [53]
The keyboard is divided into four sections: alphabetical keys, function keys, cursor keys, and the numeric keypad.  Additional special-purpose keys perform specialized functions.  The mouse is a pointing device used to input data.  Input devices enable you to input data and commands into the computer.

6 0
3 years ago
Other questions:
  • A tracking signal A. is a measurement of how well a forecast is predicting actual values. B. is computed as the mean absolute de
    13·1 answer
  • 1.What is a project methodology?
    9·1 answer
  • A construction company has an online system that tracks all of the status and progress of their projects. The system is hosted i
    10·1 answer
  • Examine the image below. What game featured characters like this that were based on the sugar skulls made for Dia de los Muertos
    15·1 answer
  • Given a voltage of 1200 volts and a current of 7 amps, what is the resistance? (# only to thousandth's place)
    14·2 answers
  • What is the clearing house for domain names called?
    12·1 answer
  • My mom hid my laptop and now I can't find it​
    9·1 answer
  • Which results are expected in a personality test but not a skills assessment?
    13·1 answer
  • Answer pleaseeeeeeeeeee!
    9·2 answers
  • Configuring a firewall to ignore all incoming packets that request access to a specific port is known as ____.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!