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
What part of the System Model is a Flow Chart primarily developed for?
Morgarella [4.7K]

A, I believe... I could be wrong

3 0
3 years ago
Which of the columns (A) to (I) in the truth table below is correct for the expression
bazaltina [42]

Answer:

tftftftftftftftftftftftftftftftftftftftftftftftftftftttttftfffftftftftttttfftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftfttftftftftftftftftftftftftftftftftftftftftftftftfttftftftfttfftftftftftftftftftftftftftfttttttttttttttttttttttfffffffffffffffffffftftftfttttttttftftftftftftftftftftftftftftftftftftftftfttftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftfftftftftftftftftfttftftftftftftftftftftftfftftftffftftfftfftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftfftfftftftftftftftftftftftftfftftftftftftftftftftftfftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftfftftftffftftftfftftftftftftftfftftftftftftftftftftftftftftftftfttftftftftftgtftftgtftgtftgtftgtftfftftfftfftfftfftftftftftftftftftftftftftftftftftftftftftfftftftftftftftftftftftftftftftfftfftfftftftftfttfftftftftftftftfftftftftftftftftftftftftftftftftftftftftftftftffftftftftftftftftftftftftftftftfftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftftfftftftftftftftftftftftftftftftftfftfftftftftftftftftftftftfftftfftftftftfftftfftftftfftftftftftftftfftftttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt

7 0
3 years ago
Read 2 more answers
For things like school, you should have a more serious:
german

Answer:

who and what do you mean

Explanation:

7 0
3 years ago
Write a program which asks the user to enter N numbers. The program will print out their average. Try your program with the foll
Likurg_2 [28]

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables

int n;

double average,sum=0,x;

cout<<"enter the Value of N:";

// read the value of N

cin>>n;

cout<<"enter "<<n<<" Numbers:";

// read n Numbers

for(int a=0;a<n;a++)

{

   cin>>x;

   // calculate total sum of all numbers

   sum=sum+x;

}

// calculate average

average=sum/n;

// print average

cout<<"average of "<<n<<" Numbers is: "<<average<<endl;

return 0;

}

Explanation:

Read the total number from user i.e "n".Then read "n" numbers from user with for loop and sum them all.Find there average by dividing the sum with n.And print the average.

Output:

enter the Value of N:5

enter 5 Numbers:20.5 19.7 21.3 18.6 22.1

average of 5 Numbers is: 20.44

7 0
4 years ago
Why do designers of smartphones hide computer processing details from
geniusboy [140]

Answer:

b.you can focus on otherthings

6 0
2 years ago
Read 2 more answers
Other questions:
  • The two types of one-time-password tokens are ______ and ______.
    10·2 answers
  • Distingush between Microkernels andexokernels
    9·1 answer
  • Because of the limited storage capacity of __________, it is unsafe to talk on a cell phone while driving on a freeway during ru
    7·1 answer
  • What are the five resources paid for by local taxes
    15·1 answer
  • Why does my inbox keep getting notifications and then disappearing?
    15·2 answers
  • Edhesive 4.6 lesson practice <br><br> Range is an example of a_______.
    10·2 answers
  • 1. PIN
    10·1 answer
  • Helllllllllppppppppppp
    9·1 answer
  • The sequence of Figures shows a pattern. if the pattern repeats, how many triangles will the figure 5 have ?​
    7·1 answer
  • All of the salespeople in hyperactive media sales use laptops, so that they can take their applications and data on the road to
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!