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]
2 years ago
11

We define the following terms:

Computers and Technology
1 answer:
Degger [83]2 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
Sarah has to add a picture from her computer file and add a caption to it. Arrange the steps in a correct sequence.
MatroZZZ [7]

Answer:

-Click insert

-Click picture

-Click from file

-Right click the picture

-Select the desired picture and again click Insert

-Click insert caption

-Write the caption and add it

Explanation:

6 0
2 years ago
What is the full form of ALU​
Alexandra [31]

Answer: arithmetic logic unit: the part of a central processing unit that performs arithmetic and logical operations.

Srry if it is wrong

I hope it  helps you

6 0
2 years ago
Read 2 more answers
Is there anybody who knows eris quirk but me- i feel lonely rn ;-;
Nutka1998 [239]

Answer:i do Eri's Quirk allows her to rewind an individual's body to a previous state. She has shown the ability to rewind someone's body to a point before they existed, which she accidentally did to her father.

3 0
3 years ago
Read 2 more answers
The cloud computing model has several unique and essential characteristics that distinguish cloud computing from an in-house inf
skelet666 [1.2K]

Answer:

Rapid Elasticity is the correct answer of this question.

Explanation:

Rapid elasticity is a cloud computing phrase for scalable storage, or the capacity to deliver scalable software. The cloud computing model has many different and necessary features which separate both cloud computing and an in-house technology. One such attribute is Rapid Elasticity.

  • The principle of rapid elasticity in specific cloud computing conditions does cause some problems.
  • The knowledge that companies still need to distribute and decommission services is often negligible on the part of the client or user.
3 0
3 years ago
How do you level up on this thing?
Gala2k [10]
You just have to answer a lot of questions, and get voted "Brainliest" by the person who posts the question
6 0
3 years ago
Other questions:
  • The four functions of a computer are
    5·1 answer
  • <img src="https://tex.z-dn.net/?f=3x%20-%205%20%3D%203x%20-%207" id="TexFormula1" title="3x - 5 = 3x - 7" alt="3x - 5 = 3x - 7"
    12·1 answer
  • 2 ways to assign a value to a variable
    6·1 answer
  • What command displays a computer s network settings?
    5·1 answer
  • which of the following is a component of a rope-rewind starter system? a. a recoil spring c. an air vane governor b. a wrist pin
    5·1 answer
  • Where or what website can I download anime's? For free ​
    6·1 answer
  • Favorite color should it be stored why?or why not?<br>​
    6·1 answer
  • (4 points.) Write an algorithm (i.e., step-by-step instructions) via which someone could walk or drive from some origin to some
    8·1 answer
  • Write down the stages in the information prcessing cycle in correct order​
    5·1 answer
  • 11111 Power 2 sovle ​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!