Answer:
- import java.util.Arrays;
- public class Main {
-
- public static void main(String[] args) {
- String [] first = {"David", "Mike", "Katie", "Lucy"};
- String [] middle = {"A", "B", "C", "D"};
- String [] names = makeNames(first, middle);
-
- System.out.println(Arrays.toString(names));
- }
-
- public static String [] makeNames(String [] array1, String [] array2){
-
- if(array1.length == 0){
- return array1;
- }
-
- if(array2.length == 0){
- return array2;
- }
-
- String [] newNames = new String[array1.length];
-
- for(int i=0; i < array1.length; i++){
- newNames[i] = array1[i] + " " + array2[i];
- }
-
- return newNames;
- }
- }
Explanation:
The solution code is written in Java.
Firstly, create the makeNames method by following the method signature as required by the question (Line 12). Check if any one the input string array is with size 0, return the another string array (Line 14 - 20). Else, create a string array, newNames (Line 22). Use a for loop to repeatedly concatenate the string from array1 with a single space " " and followed with the string from array2 and set it as item of the newNames array (Line 24-26). Lastly, return the newNames array (Line 28).
In the main program create two string array, first and middle, and pass the two arrays to the makeNames methods as arguments (Line 5-6). The returned array is assigned to names array (Line 7). Display the names array to terminal (Line 9) and we shall get the sample output: [David A, Mike B, Katie C, Lucy D]
Answer:
There should be a little icon at the bottom of your question box/answer box. It looks like a paper clip. click it and boom
Explanation:
Answer:
#include <iostream>
#include<string.h>
using namespace std;
void printCharacter(string name){
for(int i=0;name[i]!='\0';i++){
cout<<name[i]<<endl;
}
}
int main()
{
string name;
cout<<"enter the name: ";
cin>>name;
printCharacter(name);
}
Explanation:
first include the two libraries iostream for input/output and string library for using the string.
then, create the main function and declare the variable type string.
cout instruction is used o display the message on the screen.
cin is used to store the value in the name variable.
after that, call the function. The program control move to the the function. In the function for loop is used to print the character one by one until end of the name.
Answer:
Creo que necesitas crear una nueva cuenta en el Brainly español. Para encontrarlo, tal vez pueda buscar una pregunta aleatoria en Internet seguida de Brainly y, con suerte, encontrará la correcta. Luego crea una cuenta en ese Brainly. Al menos pienso cómo lo haces.
Answer:
Syntax:
For variable_name As [Data Type] = start To end [ Step step ]
For variable_name As [Data Type] = start To end [ Step step ]
[ inner loop statements ]
Next.
[ Outer loop statements ]
Next.
Explanation: