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 object waits for and responds toan event from a GUI component?
irakobra [83]

Answer:

The answer is action eventlistener

Explanation:

It is an event handler and it is easy to implement.In java we call them even listeners it is function or a sub routine or a procedure that waits for an event to occur and respond to an event from a GUI component.

8 0
3 years ago
On a digital clock the displayed time changes constantly (True or False)
Vlada [557]
The answer is true as it will change on its own
8 0
3 years ago
In Fantasy Football, participants compete against one another by choosing certain players from different NFL teams that they thi
PolarNik [594]

This process that would be considered in the above scenario is Data mining.

<h3>What is data mining?</h3>

Data mining is known to be the act or method of knowing more about data via;

  • Leaning raw data.
  • Finding patterns.
  • Forming models.
  • Testing those models.

Note that  It is a method that uses statistics, machine learning, and database systems and it will be good tool to be used in the scenario above.

Learn more about Data mining from

brainly.com/question/14776357

4 0
1 year ago
The function takes two string parameters; the first is the name of a file and the second is text. Complete the function to appen
castortr0y [4]

Answer:

The code for the function is given below in Python language

Explanation:

def append_string_to_file(filename, text):// function takes the filename // and text  to append

f = open(filename, 'a')

f.write(text) //function part that writes the text

f.close() //closing the file using the explicit close function

3 0
3 years ago
Which of the following is an advantage of text HTML editors over plain text editors?
zubka84 [21]
C hope that helps have a good day and I feel you good for big hugs
5 0
2 years ago
Read 2 more answers
Other questions:
  • You are attempting to gather information about a client's network, and are surveying a company site. Access is gained via secure
    8·1 answer
  • Given the security levels TOP SECRET, SECRET, CONFIDENTIAL, and UNCLASSIFIED (ordered from highest to lowest), and the categorie
    13·1 answer
  • A keyboard is a/an _____. interconnector port packet NAS
    7·1 answer
  • Why did Simon bring Michael home?​
    9·2 answers
  • Provide examples of the cost of quality based on your own experiences
    14·1 answer
  • How should a Salesforce Admin fulfill those requirements? Universal Containers launches a Partner Community for their resellers
    13·1 answer
  • Which option is referred to by the Reports Due tag?
    7·1 answer
  • Can someone please help me with 6.8 Code Practice adhesive.
    14·2 answers
  • You are asked to write a program that prompts the user for the size of two integer arrays, user input for the size must not exce
    13·1 answer
  • Silas develops this algorithm to compute the calories burned for an activity for a given number of minutes and body weight: If t
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!