Ex.1
Method:
Public String getStars (int count)
Description:
Compulsory Exercise 1) Complete the getStars method which is passed an int(count) as a parameter. The method returns a String containing that number of adjacent stars.
For example, getstars(3)returns “***”
If count is less than 1, returns an empty String.
An example:
getStars(3) should return “***”
public String getStars (int count) {
*** type the code here ***
}
Ex.2
Method:
public String getRowsOf3Stars (int rows)
Description:
Compulsory Exercise 2) Complete the getRowsOf3Stars method which is passed an int(rows) as a parameter. The method returns a String containing that number of 3-stars rows.
For example, getRowsOf3Stars(2) returns “***\n***\n”
If rows is less than 1, returns an empty String.
An example:
getRowsOf3Stars(2) should return "***\n***\n"
public String getRowsOf3Stars (int rows) {
*** type the code here ***
}
Ex.3
Method:
publicint sumOfOddIntegers (int max)
Description:
Compulsory Exercise 3) Complete the sumOfOddIntegers method which is passed an int(max) as a parameter. The method returns the sum of the odd integers from 1 to max (inclusive).
For example, sumOfOddIntegers(5)returns 9. (i.e. 1 + 3 + 5 = 9)
sumOfOddIntegers(8)returns 16. (i.e. 1 + 3 + 5 + 7= 16)
If max is less than 1, returns 0.
An example:
sumOfOddIntegers(5) should return 9
publicint sumOfOddIntegers (int max) {
*** type the code here ***
}
Ex.4
Method:
public String repeatString (String str, int count)
Description:
Compulsory Exercise 4) Complete the repeatString method which is passed two parameters: a String(str) and an int(count). The method returns a String consisting of the Stringstr repeated count times.
For example, repeatString("Hello", 2) returns "HelloHello"
If count is less than 1, returns an empty String.
An example:
repeatString("Hello", 2) should return "HelloHello"
public String repeatString (String str, int count) {
*** type the code here ***
}
Ex.5
Method:
public String reverseString (String str)
Description:
Compulsory Exercise 5) Complete the reverseString method which is passed a String(str) as a parameter. The method returns the Stringstr with the order of the characters reversed.
For example, reverseString(“hello”) returns “olleh”
An example:
reverseString("hello") should return "olleh"
public String reverseString (String str) {
*** type the code here ***
}
Ex.6
Method:
public double getAverage (int[] values)
Description:
Compulsory Exercise 6) Complete the getAverage method which is passed an array of ints(values) as a parameter. The method returns the average of the array of integers.
For example, if the input array is:
{3, 7, 2, 4}
the method returns 4.0
If the array is empty, returns 0.
An example:
getAverage({3, 7, 2, 4}) should return 4.0
public double getAverage (int[] values) {
*** type the code here ***
}
Ex.7
Method:
publicintcountOdds (int[] values)
Description:
Compulsory Exercise 7) Complete the countOdds method which is passed an array of ints(values) as a parameter. The method returns the number of odd numbers in the array of integers.
For example, if the input array is
{1, 2, 3, 4}
the method returns 2 because 1 and 3 are odd numbers in the array.
If the array is empty, returns 0.
An example:
countOdds({3, 7, 2, 4}) should return 2
publicintcountOdds (int[] values) {
*** type the code here ***
}
Ex.8
Method:
publicintindexOfTarget (int[] values, int target)
Description:
Compulsory Exercise 8) Complete the indexOfTarget method which is passed two parameters: an array of ints(values) and an int(target). The method returns the index position within the array of the first occurrence of the specified integer target. If target occurs in the array, then the index of the first such occurrence is returned.
For example, if the input array is
{3, 7, 2, 4} and the target is 7
the method returns 1
If no such integer occurs in this array, then -1 is returned.
An example:
indexOfTarget({3, 7, 2, 4}, 7) should return 1
publicintindexOfTarget (int[] values, int target) {
*** type the code here ***
}
Ex.9
Method:
publicintgetMin (int[] values)
Description:
Compulsory Exercise 9) Complete the getMin method which is passed an array of ints(values) as a parameter. The method returns the lowest value in the array.
For example, if the input array is
{3, 7, 2, 4}
the method returns 2.
Note: Input array must not be empty.
An example:
getMin({3, 7, 2, 4}) should return 2
publicintgetMin (int[] values) {
*** type the code here ***
}Bottom of Form
Ex.10
Method:
publicint[] reverseValues (int[] values)
Description:
Compulsory Exercise 10) Complete the reverseValues method which is passed an array of ints(values) as a parameter. The method returns the ints(values) with the order of the numbers reversed.
For example, if the input array is
{3, 7, 2, 4}
the method returns {4,2,7,3}
Note: Input array must not be empty.
An example:
reverseValues({3, 7, 2, 4}) should return {4,2,7,3}
publicint[] reverseValues (int[] values) {
*** type the code here ***
}
Need Solution Click link:
https://gum.co/wfebf
OR email me
topsolutions8@gmail.com
Method:
Public String getStars (int count)
Description:
Compulsory Exercise 1) Complete the getStars method which is passed an int(count) as a parameter. The method returns a String containing that number of adjacent stars.
For example, getstars(3)returns “***”
If count is less than 1, returns an empty String.
An example:
getStars(3) should return “***”
public String getStars (int count) {
*** type the code here ***
}
Ex.2
Method:
public String getRowsOf3Stars (int rows)
Description:
Compulsory Exercise 2) Complete the getRowsOf3Stars method which is passed an int(rows) as a parameter. The method returns a String containing that number of 3-stars rows.
For example, getRowsOf3Stars(2) returns “***\n***\n”
If rows is less than 1, returns an empty String.
An example:
getRowsOf3Stars(2) should return "***\n***\n"
public String getRowsOf3Stars (int rows) {
*** type the code here ***
}
Ex.3
Method:
publicint sumOfOddIntegers (int max)
Description:
Compulsory Exercise 3) Complete the sumOfOddIntegers method which is passed an int(max) as a parameter. The method returns the sum of the odd integers from 1 to max (inclusive).
For example, sumOfOddIntegers(5)returns 9. (i.e. 1 + 3 + 5 = 9)
sumOfOddIntegers(8)returns 16. (i.e. 1 + 3 + 5 + 7= 16)
If max is less than 1, returns 0.
An example:
sumOfOddIntegers(5) should return 9
publicint sumOfOddIntegers (int max) {
*** type the code here ***
}
Ex.4
Method:
public String repeatString (String str, int count)
Description:
Compulsory Exercise 4) Complete the repeatString method which is passed two parameters: a String(str) and an int(count). The method returns a String consisting of the Stringstr repeated count times.
For example, repeatString("Hello", 2) returns "HelloHello"
If count is less than 1, returns an empty String.
An example:
repeatString("Hello", 2) should return "HelloHello"
public String repeatString (String str, int count) {
*** type the code here ***
}
Ex.5
Method:
public String reverseString (String str)
Description:
Compulsory Exercise 5) Complete the reverseString method which is passed a String(str) as a parameter. The method returns the Stringstr with the order of the characters reversed.
For example, reverseString(“hello”) returns “olleh”
An example:
reverseString("hello") should return "olleh"
public String reverseString (String str) {
*** type the code here ***
}
Ex.6
Method:
public double getAverage (int[] values)
Description:
Compulsory Exercise 6) Complete the getAverage method which is passed an array of ints(values) as a parameter. The method returns the average of the array of integers.
For example, if the input array is:
{3, 7, 2, 4}
the method returns 4.0
If the array is empty, returns 0.
An example:
getAverage({3, 7, 2, 4}) should return 4.0
public double getAverage (int[] values) {
*** type the code here ***
}
Ex.7
Method:
publicintcountOdds (int[] values)
Description:
Compulsory Exercise 7) Complete the countOdds method which is passed an array of ints(values) as a parameter. The method returns the number of odd numbers in the array of integers.
For example, if the input array is
{1, 2, 3, 4}
the method returns 2 because 1 and 3 are odd numbers in the array.
If the array is empty, returns 0.
An example:
countOdds({3, 7, 2, 4}) should return 2
publicintcountOdds (int[] values) {
*** type the code here ***
}
Ex.8
Method:
publicintindexOfTarget (int[] values, int target)
Description:
Compulsory Exercise 8) Complete the indexOfTarget method which is passed two parameters: an array of ints(values) and an int(target). The method returns the index position within the array of the first occurrence of the specified integer target. If target occurs in the array, then the index of the first such occurrence is returned.
For example, if the input array is
{3, 7, 2, 4} and the target is 7
the method returns 1
If no such integer occurs in this array, then -1 is returned.
An example:
indexOfTarget({3, 7, 2, 4}, 7) should return 1
publicintindexOfTarget (int[] values, int target) {
*** type the code here ***
}
Ex.9
Method:
publicintgetMin (int[] values)
Description:
Compulsory Exercise 9) Complete the getMin method which is passed an array of ints(values) as a parameter. The method returns the lowest value in the array.
For example, if the input array is
{3, 7, 2, 4}
the method returns 2.
Note: Input array must not be empty.
An example:
getMin({3, 7, 2, 4}) should return 2
publicintgetMin (int[] values) {
*** type the code here ***
}Bottom of Form
Ex.10
Method:
publicint[] reverseValues (int[] values)
Description:
Compulsory Exercise 10) Complete the reverseValues method which is passed an array of ints(values) as a parameter. The method returns the ints(values) with the order of the numbers reversed.
For example, if the input array is
{3, 7, 2, 4}
the method returns {4,2,7,3}
Note: Input array must not be empty.
An example:
reverseValues({3, 7, 2, 4}) should return {4,2,7,3}
publicint[] reverseValues (int[] values) {
*** type the code here ***
}
Need Solution Click link:
https://gum.co/wfebf
OR email me
topsolutions8@gmail.com