How to figure out codes for this assignment ! /** * * @author * */ public class
ID: 3549160 • Letter: H
Question
How to figure out codes for this assignment !
/**
*
* @author
*
*/
public class ArrayAssignment {
/**
* Fill the array "a" with odd numbers starting from 111.
*
* For example, if the array had room for 3 ints, then they should be
* 111, 113, 115
*
* @param a the array to fill
* @return the finished array
*/
public static void fillWithOddsStartingAt111(int [] a){
}
/**
* The method should return the number of trues in the array
*
* @param a the array to use
* @return the number of trues in the array
*/
public static int countTheTrues(boolean [] a){
return -1;
}
/**
* This method should make an array of doubles the correct size.
* The array should be empty of any numbers (don't fill it with anything)
*
* @param numberOfLocations the size of the array
* @return a new array of doubles
*/
public static double [] makeAnArray(int numberOfLocations){
return null;
}
/**
*
* This method should return as a string everything in the array separated
* by a space
*
* For example, if the array contained the following ints 5, 2, 9, and 1
* the method should return a string that contains "5 2 9 1"
*
* @param a the array to use
* @return what is in the array separated by a single space
*/
public static String returnWhatIsInTheArrayAsAString(int [] a){
return null;
}
/**
*
* This method should return as a string everything in the array per row
* and each column as a newline
* newline is " "
*
* For example, your method should return something like
*
* "Hello
* AbuHamad
* ThisWasFun
* "
*
* (No extra spaces, but there is an extra newline at the end)
* (each row might have a different amount of characters)
*
* @param a the array to use
* @return what is in the array separated by a single space
*/
public static String returnWhatIsInTheArrayAsAString(char [][] a){
return null;
}
}
Explanation / Answer
please rate - thanks
/**
*
* @author
*
*/
public class ArrayAssignment {
/**
* Fill the array "a" with odd numbers starting from 111.
*
* For example, if the array had room for 3 ints, then they should be
* 111, 113, 115
*
* @param a the array to fill
* @return the finished array
*/
public static void fillWithOddsStartingAt111(int [] a){
for(int i=0;i<a.length;i++)
a[i]=111+i*2;
}
/**
* The method should return the number of trues in the array
*
* @param a the array to use
* @return the number of trues in the array
*/
public static int countTheTrues(boolean [] a){
int count=0,i;
for(i=0;i<a.length;i++)
if(a[i])
count++;
return count;
}
/**
* This method should make an array of doubles the correct size.
* The array should be empty of any numbers (don't fill it with anything)
*
* @param numberOfLocations the size of the array
* @return a new array of doubles
*/
public static double [] makeAnArray(int numberOfLocations){
double [] a=new double[numberOfLocations];
return a;
}
/**
*
* This method should return as a string everything in the array separated
* by a space
*
* For example, if the array contained the following ints 5, 2, 9, and 1
* the method should return a string that contains "5 2 9 1"
*
* @param a the array to use
* @return what is in the array separated by a single space
*/
public static String returnWhatIsInTheArrayAsAString(int [] a){
String s="";
for(int i=0;i<a.length;i++)
s=s+a[i]+" ";
return s;
}
/**
*
* This method should return as a string everything in the array per row
* and each column as a newline
* newline is " "
*
* For example, your method should return something like
*
* "Hello
* AbuHamad
* ThisWasFun
* "
*
* (No extra spaces, but there is an extra newline at the end)
* (each row might have a different amount of characters)
*
* @param a the array to use
* @return what is in the array separated by a single space
*/
public static String returnWhatIsInTheArrayAsAString(char [][] a){
String s="";
for(int i=0;i<a.length;i++)
{for(int j=0;j<a[i].length;j++)
s=s+a[i][j];
s=s+' ';
}
return s;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.