Answer:
public ArrayList onlyBlue(String[] clothes){
ArrayList<String> blueCloths = new ArrayList<>();
for(int i =0; i<clothes.length; i++){
if(clothes[i].equalsIgnoreCase("blue")){
blueCloths.add(clothes[i]);
}
}
return blueCloths;
}
Explanation:
- Create the method to accept an Array object of type String representing colors with a return type of an ArrayList
- Within the method body, create and initialize an Arraylist
- Use a for loop to iterate the Array of cloths.
- Use an if statement within the for loop to check if item equals blue and add to the Arraylist.
- Finally return the arrayList to the caller
Answer:
Following is the expression written in "Bash script" (mixture of commands):
^\d{5}(?:[-\s]\d{4})?$
Explanation:
- ^ = For staring string (denotation).
- \d{5} = Matching 5 digits (first five unknown x's)
- (?:…) = Making Group (making group of former 5 digits)
- [-\s] = Match a hyphen or a space
(checking if a hyphen is present?)
- \d{4} = Matching 4 digits (next four unknown x's)
- …? = Pattern before it is optional
- $ = Ending of the string.(denotation)
According to the given question, sales is a two-dimensional array and contains 10 rows and 7 columns wherein each component is of type integer and the variables sum and j are also of integer type.
<u>Explanation:</u>
In order to find the sum of the elements of the fifth row of sales, the correct piece of code should be:
sum=0;
for(j=0;j<7;j++)
sum=sum+sales[4][j];
The indexing in an array always starts from zero, therefore, to calculate the sum of the fifth row, the user has to write 4 in the index to point to the fifth row.
Sepa la verga cx I don't even know this