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
Ilia_Sergeevich [38]
3 years ago
9

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

cter of the value of name. So if the value of name were "Smith" the expression's value would be 'S'.
Computers and Technology
1 answer:
Nostrana [21]3 years ago
5 0

Answer:

char firstLeter = name.charAt(0);

Explanation:

Consider the program below:

public class num2 {

   public static void main(String[] args) {

     String name = "Smith";

     char firstLetter = name.charAt(0);

       System.out.println(firstLetter);

   }

}

In this program, A string name is defined and assigned the value "Smith".

Java's String method charAt() is called and passed the argument of index 0. This causes it to output the character S. Since this is the first letter in the String is at index 0.

You might be interested in
Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in
notsponge [240]

Answer:

count = 20

i = 0

short_strings = []

long_strings = []

while(i<count):

   s = input("Enter a string: ")

   

   if s == "ZZZ":

       break

   

   if len(s) <= 10:

       short_strings.append(s)

   elif len(s) >= 11:

       long_strings.append(s)

   

   i += 1

choice = input("Enter the type of list to display [short/long] ")

if choice == "short":

   if len(short_strings) == 0:

       print("The list is empty.")

   else:

       print(short_strings)

else:

   if len(long_strings) == 0:

       print("The list is empty.")

   else:

       print(long_strings)

Explanation:

*The code is in Python.

Initialize the count, i, short_strings, and long_strings

Create a while loop that iterates 20 times.

Inside the loop:

Ask the user to enter a string. If the string is "ZZZ", stop the loop. If the length of the string is smaller than or equal to 10, add it to the short_strings. If the length of the string is greater than or equal to 11, add it to the long_strings. Increment the value of i by 1.

When the loop is done:

Ask the user to enter the list type to display.

If the user enters "short", print the short list. Otherwise, print the long_strings. Also, if the length of the  chosen string is equal to 0, print that the list is empty.

3 0
4 years ago
. Why should we favor programming to interfaces over implementations?
xenn [34]

Answer:

Interfaces are way to use full abstraction.That;s why it is preffered over implementations.

Interfaces are just like class.But the methods declared inside an abstract class are by default abstract and the variables are by default static,final.Which is not the case with classes in classes the variables can be static or non- static ,fincal or non-final and methods can be abstract or non-abstract.

Java classes does not support multiple inheritance but interfaces support multiple inheritance.So whenever we want to implement multiple inheritance in Java we use interfaces.

4 0
3 years ago
2.
Sauron [17]
Im pretty sure it is b
7 0
3 years ago
8.17 Lab: Strings of a Frequency Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, th
gavmur [86]

Answer:

def occurencesOfWords(words,freq):

  frequency_dictionary={}

  matched_frequency_words=[]

  for i in range(len(words)):

      counter=1

      a=words[i].lower()

      for j in range(len(words)):

          if(i==j):

              continue

          b=words[j].lower()

          if(a==b):

              counter+=1

      frequency_dictionary[words[i]]=counter

  for key in frequency_dictionary:

      if(frequency_dictionary[key]==freq):

          matched_frequency_words.append(key)

  return matched_frequency_words

if __name__=='__main__':

  user_input=input()

  freq=int(input())

  words=user_input.split(" ");

  required_words=occurencesOfWords(words,freq)

  for s in required_words:

      print(s)

Explanation:

  • Inside the occurencesOfWords function, initialize a frequency_dictionary that is used to store the string and the frequency of that specific string .
  • matched_frequency_words is an array that is used to store each string whose frequency matches with the provided frequency
  • Run a nested for loop up to the length of words and inside the nested for loop, skip the iteration if both variables i and j are equal as both strings are at same index.
  • Increment the counter variable, if two string are equal.
  • Loop through the frequency_dictionary to get the matching frequency strings .
  • Finally test the program inside the main function.
5 0
3 years ago
Write a C++ program that computes an approximation of pi (the mathematical constant used in many trigonometric and calculus appl
Verizon [17]

Answer:

#include <iostream>

#include<cmath>

using namespace std;

int main()

{

double total = 0;

double check=1;

double ct=0;

double old=1;

while( fabs(total - old) > 0.00005 )

{

old=total;

total=total+check*4.0/(2.0*ct+1);

ct=ct+1;

check=0.0-check;

}

cout<<"Approximate value of pi is "<<total<<endl;

return 0;

}

Explanation:

  • Initialize all the necessary variables.
  • Run a while loop until the following condition is met.

fabs(total - old) > 0.00005

  • Inside the while loop calculate the total value.
  • Lastly, display the approximate value of pi.
3 0
4 years ago
Other questions:
  • If you want three vertical sections of text on your page, create _____.
    11·2 answers
  • Which group on the Home Ribbon contains the line spacing attribute?
    9·2 answers
  • What is a series of instructions or commands that a computer follows used to create software
    9·1 answer
  • When converting old html code to xhtml, make sure to replace the ____ attribute with the background-color style?
    10·1 answer
  • Which categories format cells
    14·2 answers
  • In Windows applications, a ____ control is commonly used to perform an immediate action when clicked.a. text boxb. buttonc. wind
    7·1 answer
  • Nina is 12 years old. She has just changed her password and wants to make sure she has it in case of
    15·2 answers
  • A non technical kind of cyber intrusion that relies heavily on human interaction and often involve tricking people into breaking
    5·1 answer
  • The if statement regards an expression with the value 0 as __________.
    13·1 answer
  • What are the five generations of computers?​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!