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
The guy wire BD exerts on the telephone pole AC a force P directed along BD. Knowing that P must have a 720-N component perpendi
AysviL [449]

Answer:

Explanation:

  • From the diagram, tanФ = opp/Adj = 2.4m/7m
  • tanФ = 0.3429. Ф = arctan ( 0.3429 )
  • Therefore, Ф = 18.92°

Given force perpendicular to AC from the diagram = 720N

  • Resolving vertically; PsinФ = 720

a) P = 720/sin18.92° = 2220N = the magnitude of the force P

b) To get component along line AC;

  • resolving horizontally, component along AC = PcosФ
  • = 2220 x cos 18.92° = 2100N

8 0
4 years ago
Which applicants would be best suited for which jobs based on educational and training? Boris is best suited to be an Electricia
Triss [41]

Boris, Mona, and Jody  are best suited to work with electricity in the first set of sentences. The second sentences Boris and Boyd are best suited to be engineers, and finally they all are good candidates for the job.

8 0
3 years ago
Read 2 more answers
How many hours did it take supercomputer to calculate pi?
dybincka [34]
35 hours to be exact
3 0
3 years ago
The emergence of MP3 (iPod) technology is an example of creative destruction because a. It is less expensive than compact discs
Katen [24]

Answer:

The emergence of MP3 (iPod) technology is an example of creative destruction because it has b. Replaced compact discs as a technology used for the storage and transfer of music.

Explanation:

Creative destruction refers to the process whereby a new technology/product replaces the one before it. The MP3 technology replaced compact discs because people started using MP3 files to transfer and store music since it was less expensive and files could be transferred easily. MP3 files could be transferred over Bluetooth and they required less storage space. Whereas, a compact disc required more space and costed more as well. So, MP3 technology replaced compact discs.

The emergence of MP3 (iPod) technology is an example of creative destruction because it has b. Replaced compact discs as a technology used for the storage and transfer of music.

8 0
3 years ago
List and describe the tools for all the main stages of app/application development.
Liono4ka [1.6K]
<span>stuff like -Information Gathering -Planning -Design -Development -Testing and Delivery <span>Maintenance hope that helped.</span></span>
8 0
3 years ago
Other questions:
  • Alice has to move around a lot to fetch objects at her workstation. Which ergonomic principle should Alice follow to prevent str
    8·2 answers
  • Your computer is slowing down because you’ve started a process that is taking most of the memory and CPU resources. Which of the
    7·1 answer
  • The _______________ is a priority-ordered list of the other carrier networks and frequencies it should search for when it cannot
    6·1 answer
  • A technician is using a network-attached desktop computer with a Type 2 hypervisor to run two VMs. One of the VMs is infected wi
    14·1 answer
  • One of the most common causes of fires in the home and workplace is: a. All of the answer choices b. Arson c. Candle d. Faulty e
    6·1 answer
  • All of these (except the ______) go unnoticed by the computer
    7·1 answer
  • What is digital scavenger hunting? A. An application that locates addresses B. A scavenger hunt where players use GPS and digita
    5·1 answer
  • 6 → What is the difference between SHA-256 and SHA-512?
    12·1 answer
  • Question 1 (1 point)
    9·2 answers
  • Tools used to build a bridge<br>​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!