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
Nana76 [90]
3 years ago
6

Assuming that s and t are Strings, which of the following code fragments are such that the value returned by s.indexOf( t ) befo

re the code is executed is equal to the value of the int n after the code is executed?
I. int n = -1;
int tSize = t.length();
boolean found = false;
while ( !found && tSize <= s.length() )
{
n++;
if ( t.equals( s.substring( 0, tSize ) ) )
found = true;
else
s = s.substring( 1 );
}
if ( !found )
n = -1;
II. int n = -1;
int sSize = s.length();
int tSize = t.length();
boolean found = false;
while ( !found && n + tSize + 1 <= sSize )
{
n++;
if ( t.equals( s.substring( n, n + tSize ) ) )
found = true;
}
if ( !found )
n = -1;
III. int n = 0;
int sSize = s.length();
int tSize = t.length();
boolean found = false;
while ( !found && n + tSize <= sSize )
{
if ( t.equals( s.substring( n, n + tSize ) ) )
found = true;
n++;
}
if ( found )
n--;
else
n = -1;
A. I only
B. II only
C. III only
D. I and II only
E. I, II, and III
Computers and Technology
1 answer:
KengaRu [80]3 years ago
5 0

Answer:

What programming language is this

Explanation:

You might be interested in
What are the core scripting and coding technolies used to build ai platforms?
boyakko [2]
<span>Artificial Intelligence is a huge field. </span>
4 0
3 years ago
A certain list, L, contains a total of n numbers, not necessarily distinct, that are arranged in increasing order. If L1 is the
Free_Kalibri [48]

In this question, we are given ,

  • A certain list, L, contains a total of n numbers, not necessarily distinct, that are arranged in increasing order.
  • L1 is the list consisting of the first n1 numbers in L.
  • L2 is the list consisting of the last n2 numbers in L.

Explanation:

As per the information given in statement 1, 17 is a mode for L1 and 17 is a mode for L2.

Therefore, we can infer that ,

  • 17 must occur in L1, either same or a greater number of times as any other number in L1.
  • 17 must occur in L1, either same or a greater number of times as any other number in L2.

As all elements in L are in ascending order, we can also conclude that

  • Each number between last occurrence of 17 in L1 and the first occurrence of 17 in L2 must be equal to 17 only.
  • Therefore, 17 occurs either same or greater number of times as any other number in L.
  • Thus, 17 is a mode for L.

However, from this statement, we cannot conclude anything about the mode of L1, L2, or L.

Hence, statement 2 is not sufficient to answer the question.

Therefore, 17 is a mode for L1 and 17 is a mode for L2.

3 0
3 years ago
Create a text file that contains your expenses for last month in the following categories: • Rent • Gas • Food • Clothing • Car
ololo11 [35]

Answer:

Check the explanation

Explanation:

Code:

import matplotlib.pyplot as plt

filename = input('Enter the name of file : ')

# open file in read mode

fptr = open(filename , 'r')

# set the labels

categories = [ 'Rent', 'Gas', 'Food', 'Clothing', 'Car Payment', 'Misc' ]

# store the expenses in the order of labels

expenses = []

# read the content of file

strng = fptr.read()

# read the file line by line

for line in strng.split('\n'):

   # add the current expense to expenses

   expenses.append( int( line ) )

colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue', 'green', 'red']

# plot the pie chart

plt.pie(expenses, labels = categories, colors = colors, autopct='%1.1f%%', shadow=True, startangle=140)

# set the axis as equsl

plt.axis('equal')

# display the chart

plt.show()

------------------------------input.txt--------------------------

1000

235

5600

800

480

758

Kindly check the attached output image below.

3 0
4 years ago
True/False: A binary search looks for a desired item by comparing the search item to each data item in order, from first to last
Harrizon [31]

Answer: False

Explanation: a binary search divides the list into halves that could contain the item until it narrows down only to one item.

5 0
2 years ago
Read 2 more answers
Assume that input file references a Scanner object that was used to open a file. Which of the following while loops shows the co
Brut [27]

while (!inputFile.EOF) loops shows the correct way to read data from the file until the end of the file is reached.

b. while (!inputFile.EOF)

<u>Explanation:</u>

Normally to read an input files as loop the program reads till end of file mark been seen.  A loop been executed till an EOF is reached.

End user has to write a logic in software languages  which should have a loop and ready a bit or set of bits which depends of end user technology and stop reading till end of file which is called  EOF = true.  

If EOF is not true then end user program loop never ends and program is either hang or bug or goes to really task.

End user has check either EOF = True or files size reach to end of bytes. Whichever comes first.

Otherwise if EOF is not true then it is corrupted files.

4 0
3 years ago
Other questions:
  • Which of these are examples of skills?
    5·2 answers
  • To track conversions in an app, you can add the firebase sdk to your app. sdk stands for:
    5·1 answer
  • Suppose you use Batch Gradient Descent to train a neural network and you plot the training error at every epoch. If you notice t
    7·1 answer
  • Explain what is meant by information technology (IT). Explain what is meant by information systems (IS). Why is it important to
    7·1 answer
  • Which are technical and visual demands<br> that need to be considered when<br> planning a project?
    6·1 answer
  • Hubs connect network hosts in which configuration?
    7·1 answer
  • Please helpppppppppppppppppp please I’m stuck!
    15·1 answer
  • When adding a new record, which key can be pressed to move to the next field?
    10·1 answer
  • Identify the type of error.<br> print "hello"<br><br> num = 5 / 0
    11·2 answers
  • ONLY ANSWER IF YOU KNOW HOW TO WRITE THIS CODE
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!