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
Alla [95]
3 years ago
11

1. Assume that word is a variable of type String that has been assigned a value . Assume furthermore that this value always cont

ains the letters "dr" followed by at least two other letters. For example: "undramatic", "dreck", "android", "no-drip".
Assume that there is another variable declared , drWord, also of type String . Write the statements needed so that the 4-character substring word of the value of word starting with "dr" is assigned to drWord. So, if the value of word were "George slew the dragon" your code would assign the value "drag" to drWord.

2. Assume that sentence is a variable of type String that has been assigned a value . Assume furthermore that this value is a String consisting of words separated by single space characters with a period at the end. For example: "This is a possible value of sentence."

Assume that there is another variable declared , firstWord, also of type String . Write the statements needed so that the first word of the value of sentence is assigned to firstWord. So, if the value of sentence were "Broccoli is delicious." your code would assign the value "Broccoli" to firstWord.
Computers and Technology
1 answer:
s2008m [1.1K]3 years ago
4 0

Answer:

1.word = "George slew the dragon"

startIndex = word.find('dr')

endIndex = startIndex + 4

drWord = word[startIndex:endIndex]

2. sentence = "Broccoli is delicious."

sentence_list = sentence.split(" ")

firstWord = sentence_list[0]

Explanation:

The above snippet is written in Python 3.

1. word is initialized to a sentence.

Then we find the the occurence of 'dr' in the sentence which is assign to startIndex

We then add 4 to the startIndex and assign it to endIndex. 4 is added because we need a length of 4

We then use string slicing method to create a substring from the startIndex to endIndex which is assigned to drWord.

2. A string is assigned to sentence. Then we split the sentence using sentence.split(" "). We split based on the spacing. The inbuilt function of split returns a list. The first element in the list is assigned to firstWord. List uses zero based index counting. So. firstWord = sentence_list[0] is use to get first element.

You might be interested in
Given the following class, public class Magazine { private static double SUBSCRIPTION_DISCOUNT = .60; private String title;
jonny [76]

Answer:

The answer is "III only"

Explanation:

An accessor method is also an instance function that receives or establishes the value of an object's properties. This method is called methods through obtaining information about an entity. This method reverses it to process, which has two accessory string techniques to reach source string data reference length Accessor method.

6 0
3 years ago
Write an exception tester application that enables you to see the impact of exceptions being thrown. Include multiple catch clau
AveGali [126]

Answer:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("\t\tHandling Exceptions Program");

Console.WriteLine("\n\tArithmetic Exception:\n");

// Arithmetic Exception is base class of DivideByZero Class

// Hence will be using DivideByZero Exception

int b = 0;

try

{

//Attempting Divide BY Zero

int myBadMath = (5 / b);

}

catch (System.DivideByZeroException ex)

{

Console.WriteLine("Error : Trying to divide a number by Zero");

}

//FormatException example

//Used when formats DO NOT match a data type

Console.WriteLine("\n\tFormat Exception:\n");

Console.WriteLine("Please enter a number :");

string str = Console.ReadLine();

double dNo;

try

{

//throws exception when a string is entered instead of a number

dNo = Convert.ToDouble(str);

Console.WriteLine(dNo+" : Is a valid number");

}

catch (FormatException ex)

{

Console.WriteLine("Error : "+str+" is not a valid number");

}

//IndexOutOfRangeException example

//Thrown when an element is attempted to assign or read out of the array size

Console.WriteLine("\n\tIndexOutOfRangeException Exception:\n");

try

{

//5 element array declared

int[] IntegerArray = new int[5];

//attempting 10th element. Hence error is thrown

IntegerArray[10] = 123;

}

catch (IndexOutOfRangeException)

{

Console.WriteLine("An invalid element index access was attempted.");

Console.Read();

}

}

}

}

Explanation:

8 0
3 years ago
Outputting all combinations. Output all combinations of character variables a, b, and c using this ordering abc acb bac bca cab
Alina [70]

Answer:

#include<iostream>

using namespace std;

 

int main()

{

   char a;  

   char b;  

   char c;

cin >> a;  

cin >> b;  

cin >> c;

 cout<<a<<b<<c<<endl;

 cout<<a<<c<<b<<endl;

 cout<<b<<a<<c<<endl;

 cout<<b<<c<<a<<endl;

 cout<<c<<a<<b<<endl;

 cout<<c<<b<<a<<endl;

 

cout << endl;

}

Explanation:

Note: code is hard coded it does not contain any logic based coding

5 0
3 years ago
What allows you to jump to a specific pet of a document
Viefleur [7K]

Answer:

C - Go-To

Explanation:

You would be "Going To" a part of the page.

6 0
2 years ago
Does this look anywhere close to the APA Format?
Galina-37 [17]
Make sure your font is set to Times. And font size set at 12. 1 in from the border. Make sure to indent your paragraphs. And site anything you used, that is not your words. I find you still did great!
4 0
3 years ago
Other questions:
  • A circuit contains two 500 OHM resistors connected in parallel and is supplied with 60 VDC. What is the current in the circuit?
    12·2 answers
  • Browsing the web is one of the most common activities performed by individuals who use computers.
    12·1 answer
  • The create_python_script function creates a new python script in the current working directory, adds the line of comments to it
    9·1 answer
  • Know when the double, int, String, and char data types are best used. Example: I would store a social security number in a strin
    7·1 answer
  • Buenas , ayudenme con esta tarea de excel 2016
    6·1 answer
  • You are running out of storage space on one of your servers. you need to purchase an external hard drive, as there are no drive
    8·2 answers
  • What is percent encoding and why is it used?
    10·1 answer
  • hey guys just dropped some hot beats so go and follow me my user is the beats and comment if you would do that that would be gra
    11·1 answer
  • What types of user permissions can you set up when adding a new team member in QuickBooks Online Accountant?
    15·1 answer
  • i need help with this my laptop is not let me connet to my wifi and when i try to add out wifi if says "connect Failed" please h
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!