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
leva [86]
3 years ago
6

What is wrong with each of the following code segments?

Computers and Technology
1 answer:
Arte-miy333 [17]3 years ago
6 0

Answer:

a. ArrayList values = new ArrayList();

Correct way:  ArrayList<Type> values = new ArrayList<>();

b. ArrayList values = new ArrayList();

Correct way:  ArrayList<Type> values = new ArrayList<>();

c. ArrayList values = new ArrayList;

Correct way:  ArrayList<Type> values = new ArrayList<>();  

d. ArrayList values = new ArrayList();

for (int i = 1; i <= 10; i++) {

values.set(i - 1, i * i);

}

Correct way:  

ArrayList<Integer> values = new ArrayList<>();  

for (int i = 1; i <= 10; i++) {

*At this point size of the array is 0*

values.set(i - 1, i * i);  

* "set()" method is used to set an element in an ArrayList object at the specified index and in this line is wrong bcz u have no objects added in your ArrayList. *

}

e. ArrayList values;  --> You have to initialize the ArrayList

for (int i = 1; i <= 10; i++) {

values.add(i * i);  }

Correct way:  

ArrayList<Integer> values = new ArrayList<>();  

for (int i = 1; i <= 10; i++) {

values.add(i * i);  }

You might be interested in
A user logs in to a virtual world and creates an animated character representing themselves, which they then use to move through
Romashka [77]

A type of animated character that represents a user in the virtual world, which is used to move throughout the world and interact with other characters and objects is called an <u>avatar</u>.

<h3>What is an avatar?</h3>

An avatar can be defined as a type of animated character that is designed and developed by a software developer to represent a user or player in the virtual world, which is used to move throughout the world and interact with other characters and objects.

In gaming technology and software development, an avatar is typically used to denote a user's (player's) character in the gaming world, virtual world or computer-simulated environment, either in two-dimensional (2D) or three-dimensional (3D).

Read more on avatar here: brainly.com/question/26479902

4 0
3 years ago
Read 2 more answers
One subtask in the game is to roll the dice. explain why is roll the dice an abstraction.
LUCKY_DIMON [66]

Answer:

A game is built from a combination of sub-tasks in order to provide the best experience to the user and make sure that the interface is comprises of only the results of the ongoing sub-tasks to provide a higher degree of data abstraction.

Data abstraction refers to the process of representing the essential information without including the background details. Rolling a dice is preferred to be a sub-task so that the user only gets to know about the result of the roll and does not have to wait for or anticipate the result. Moreover, a game may consist of n number of sub-tasks so it is not a good idea to include them in the main framework and are preferred to be abstracted.

4 0
3 years ago
Write the following function without using the C++ string class or any functions in the standard library, including strlen(). Yo
dolphi86 [110]

Answer:

The function in C++ is as follows

int chkInd(string str1, string str2){    

int lenstr1=0;

while(str1[lenstr1] != '\0'){  lenstr1++;  }

int index = 0; int retIndex=0;

for(int i=lenstr1-1;i>=0; i--){

   while (str2[index] != '\0'){

       if (str1[i] == str2[index]){

           retIndex=1;

           break;         }

       else{   retIndex=0;      }

  index++;    }

  if (retIndex == 0){   return i;   }else{return -1;}}

}

Explanation:

This defines the function

int chkInd(string str1, string str2){    

First, the length of str1 is initialized to 0

int lenstr1=0;

The following loop then calculates the length of str1

while(str1[lenstr1] != '\0'){  lenstr1++;  }

This initializes the current index and the returned index to 0

int index = 0; int retIndex=0;

This iterates through str1

for(int i=lenstr1-1;i>=0; i--){

This loop is repeated while there are characters in str2

   while (str2[index] != '\0'){

If current element of str2 and str1 are the same

       if (str1[i] == str2[index]){

Set the returned index to 1

           retIndex=1;

Then exit the loop

           break;         }

If otherwise, set the returned index to 0

       else{   retIndex=0;      }

Increase index by 1

  index++;    }

This returns the calculated returned index; if no matching is found, it returns -1

  if (retIndex == 0){   return i;   }else{return -1;}}

}

4 0
3 years ago
Edward scissorhands Of course, Jim is the villain, but who or what is the antagonist in the film? Explain in detail.
Doss [256]
Jim is the main antagonist while Edward is the main protagonist of the movie.
8 0
3 years ago
The ip address 172.16.80.125 is written in binary notation as:
trasher [3.6K]
10101100.00101001000
8 0
4 years ago
Other questions:
  • The most effective way to perform data entry is to keep your hands on the keyboard and press to move to the text cell in the row
    10·1 answer
  • ____ data exist in a format that does not lend itself to processing that yields information.
    8·1 answer
  • F a domain consists of dcs that are running verions of windows server earlier than windows server 2008, what replication method
    10·1 answer
  • write a program that reads in the length and the width of a rectangular yard . your program should compute the time required ( i
    5·1 answer
  • What is WEB 1.0 to WEB3.0
    11·1 answer
  • Which of these are examples of a bug?
    6·1 answer
  • What is the importance of effectiveness in communication?
    14·1 answer
  • What is the missing line of code? &gt;&gt;&gt; &gt;&gt;&gt; math.sqrt(16) 4.0 &gt;&gt;&gt; math.ceil(5.20) 6
    14·2 answers
  • Write the name of main ore of silver.Write any two application of sliver​
    14·1 answer
  • One way to protect against a security threat to a computer system is to __________. Avoid external links with inconsistent URLs
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!