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
Simora [160]
3 years ago
6

Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is a String contai

ning the last character of the value of name. So if the value of name were "Smith" the expression's value would be "h".Given a String variable named sentence that has been initialized, write an expression whose value is the number of characters in the Stringreferred to by sentence.Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is a String containing the last character of the value of name. So if the value of name were "Smith" the expression's value would be "h".
Computers and Technology
1 answer:
Stella [2.4K]3 years ago
3 0

Corrected (Modified) Question:

i. Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is a String containing the last character of the value of name. So if the value of name were "Smith" the expression's value would be "h".

ii. Given a String variable named sentence that has been initialized, write an expression whose value is the number of characters in the String referred to by sentence.

Explanation of the corrected question

The whole question has been numbered (i) and (ii) just to separate or divide it into clearer sub questions.

Some parts of the question has also been removed since they are repetition of a part of the question.

Answer:

(i) name.charAt(name.length() - 1)

(ii) sentence.length()

Explanation:

No language  has been specified in the question for the code to be written in. However, I have chosen to write it in Java.

(i) In Java, to get a particular character in a string <em>str</em>, the function, charAt(x) is used, where x in the function represents the index of the character to be fetched. This is written as str.charAt(x).

In our case, x is the index of the last character in our string. To get the index of the last character in a string say <em>str</em>, the length of the string itself is used. However, indexing starts at zero. Therefore, to get the index, it will be the 1 subtracted from the length of the string as follows:

str.length() - 1

But note that, to get the length of a string, the method length() is used. For example if,

String str = "omobowale";

str.length() will return 9

Now to the question at hand, our string variable name is <em>name. </em>

Therefore to get its last character, we write:

<em>name.charAt(name.length() - 1)</em>

So if;

name = "Smith";

name.charAt(name.length() - 1) will return "h"

(ii) As explained in (i) above, to get the length (number of characters) of the variable string <em>sentence, </em>we simply write;

<em>sentence.length()</em>

<em>PS: The length of  a string is the number of characters present in the string.</em>

Hope this helps!

You might be interested in
Which of the following would most likely be the target audience for a product
inna [77]

Answer:

B

Explanation:

They are saturday morning cartoons. Saturday morning cartoons are meant towards an audience of young children.

3 0
3 years ago
Read 2 more answers
Use the drop-down menus to complete the statements about printing Contacts. When printing a single contact, go to File and then
UkoKoshka [18]

Answer:

When printing a single contact, go to File and then Print; the only style available is Memo style .

When printing multiple contacts, there are several styles to choose from

Explanation:

<em>The question has been answered (by you). I will help you with the explanation. The texts in bold in the answer section represent the answer.</em>

<em />

The question is an illustration of Microsoft outlook.

In Microsoft outlook, the default style of printing is the memo style of printing. This is the only form of printing allowed when printing single contacts. In other words, other forms of printing cannot be selected.

However, there are several options available when multiple contacts are to be printied. Some of the printing styles are:  phone directory style, card style, medium booklet style, etc.

8 0
3 years ago
Which is the first calculating device invented?​
denis-greek [22]

Answer:the abacus

Explanation:

3 0
2 years ago
Read 2 more answers
Pda bkhhksejc pnwjoynelp dwo xaaj ajykzaz ywj ukq zaykza ep???<br><br><br> The Key Value is 22
Sindrei [870]

Answer:

The following transcript has been encoded can you decode it???

Explanation:

It is a ceasar cipher. Shift every letter in the alphabet by 22 positions.

3 0
4 years ago
In modern computer systems, a byte consists of
Cerrena [4.2K]
8 smaller units, called bits :)
8 0
3 years ago
Other questions:
  • 24 bit or 16 million colors is often called?
    7·1 answer
  • Which of the following is not a shared characteristic of new media.
    8·1 answer
  • Public-key cryptography can be used for encryption (ElGamal for instance) and key exchange. Furthermore, it has some properties
    9·2 answers
  • After you have located a program name from the Start menu, in order to create a shortcut on the desktop.
    8·1 answer
  • Can you help me with this question please ​
    13·1 answer
  • The data _____ component of a database management system (DBMS) is used to create and maintain the data dictionary.
    12·1 answer
  • Glenda is searching airline schedules on HolApp, a mobile Web application. While browsing the application, a banner appears on t
    12·1 answer
  • What does the asterisk (*) after select tell the database to do in this query?
    6·1 answer
  • Which directory contains the initrd file? in suse linux
    11·1 answer
  • Which backup requires a small amount of space and is considered to have an involved restoration process?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!