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
How do you put a voice password on your computer using windows 10
valkas [14]
I think you need some time of camra voice recorder sorry if im wrong also sorry cuz i forgot what it is called
7 0
2 years ago
Apakah ada yang bisa menjelaskan potongan source code ini?
GarryVolchara [31]

This code attempts to fuse two strings together. So,

fuse("Apple", "Banana")

would return "ABpapnlaen a"

However, there are a couple of things wrong with this code:

- The for loop is incomplete (probably a copy paste error)

- It is unclear from the code if the array jawaban will overflow if kata1 and kata2 are large (it probably will)

- Biggest problem: the jawaban array is declared on the stack, which means it will be cleaned up when the function returns. So the caller of this function will reference unallocated memory! This is a huge bug!!

6 0
3 years ago
Drag the tiles to the correct boxes to complete the pairs.
sertanlavr [38]

Answer:

Explanation:

IaaS - storage and network devices

SaaS - software upgrades and patches

MaaS - monitoring tools

PaaS - virtual computing platform

7 0
2 years ago
Assume that a gallon of paint covers about 350 square feet of wall space. Create anapplication with a main() method that prompts
Elena-2011 [213]

Answer:

import java.util.Scanner;

public class PaintClculator {

   public static void main(String[] args) {

Scanner in = new Scanner(System.in);

       System.out.println("Enter Values for length, width, and height of the room");

       double length = in.nextDouble();

       double width = in.nextDouble();

       double height = in.nextDouble();

       double wallArea = calculateWallArea(length,width,height);

       double noGallons = calculatePaint(wallArea);

       double price = price(noGallons);

       System.out.println("Price is: "+ price);

   }

   // Creating Method to Calculate Wall Area

   public static double calculateWallArea( double length, double width, double height){

       // formular for the surface area of a room Area=2*length*heigth+2*width*height+lenth*width

       double Area = 2*length*height+2*width*height+length*width;

       System.out.println("Wall Area: "+Area);

       return Area;

   }

   //Creating method to calculate amount of paint

   public static double calculatePaint(double Area){

       double noGallons = Area/350;

       System.out.println("Number of gallons: "+noGallons);

       return noGallons;

   }

   // Creating Method Calculate Price

   public static double price(double noGallons){

       return noGallons*32;

   }

}

Explanation

  1. Created Three Methods in all; calculateWallArea(), calculatePaint(), and price()
  2. Method calculateWallArea() calculates area based on this formula Area=2*length*heigth+2*width*height+lenth*width
  3. The value of Area is passed to method calculatePaint() Which calculates the number of gallons required to cover the area given that one gallon covers 350 wall space
  4. Method price() calculates and dis[plays the price by calling method calculatePaint() that returns number of gallons. since one gallon is 32$
3 0
3 years ago
If you are using a sprite for your MakeCode Arcade game, which code block
xeze [42]

Answer:

set mySprite block

Explanation:

BRAINLIEST?

8 0
2 years ago
Read 2 more answers
Other questions:
  • Select all of the uses of presentation software in the workplace.
    8·1 answer
  • When are number list generally used ?
    10·1 answer
  • The family size bottle of sunscreen holds 121212 fluid ounces (\text{fl oz})(fl oz)(, start text, f, l, space, o, z, end text, )
    12·1 answer
  • PreparedStatement ps = connection.prepareStatement("select firstName, mi, lastName from Student where lastName = ?"; ps.setStrin
    5·1 answer
  • write the algorithm, flowchart and BASIC program to calculate the area of the rectangle length 50m and width 30m.​
    8·1 answer
  • Why are application programs stored in main memory​
    11·1 answer
  • Why is compression a "hard problem" for computers? Draw on your own experience compressing text with the text compression widget
    12·1 answer
  • 4.12 LAB: Using math methods Given three floating-point numbers x, y, and z, output x to the power of z, x to the power of (y to
    10·1 answer
  • Write code that prints: Ready! userNum ... 2 1 Go! Your code should contain a for loop. Print a newline after each number and af
    6·1 answer
  • A(n) Blank______ database management system allows users to create, read, update, and delete data in a relational database. Mult
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!