Category: Java

Assume the existence of a Widget class that implements the Comparable interface and thus has a compareTo method that accepts an Object parameter and returns an int.

4
Assume the existence of a Widget class  that implements the Comparable interface and  thus has a compareTo method  that accepts an Object parameter and returns an int.

LANGUAGE: JAVA CHALLENGE: Assume the existence of a Widget class that implements the Comparable interface and thus has a compareTo method that accepts an Object parameter and returns an int. Write an efficient static method, getWidgetMatch, that has two parameters. The first parameter is a reference to a Widget object. The second parameter is a […]

Read More

Write the definition of a method named copy receives a reference to a Scanner object associated with a stream of input.

Write the definition of a method  named  copy receives a reference  to a Scanner object  associated with a stream of input.

LANGUAGE: JAVA CHALLENGE: Write the definition of a method named copy receives a reference to a Scanner object associated with a stream of input. The method reads all the Strings remaining to be read from the stream and displays them, one on a line with no other spacing, onto standard output . The method must […]

Read More

Write the definition of a method named add that receives a reference to a Scanner object associated with a stream of input consisting of integers only.

Write the definition of a method  named  add that receives a reference  to a Scanner object  associated with a stream of input consisting of integers  only.

LANGUAGE: JAVA CHALLENGE: Write the definition of a method named add that receives a reference to a Scanner object associated with a stream of input consisting of integers only. The method reads all the integers remaining to be read from the stream and returns their sum . So if the input were 3 51 204 […]

Read More

Write the definition of a method named count that receives a reference to a Scanner object associated with a stream of input.

1
Write the definition of a method  named  count that receives a reference  to a Scanner object  associated with a stream of input.

LANGUAGE: JAVA CHALLENGE: Write the definition of a method named count that receives a reference to a Scanner object associated with a stream of input. The method reads all the Strings remaining to be read in standard input and returns their count (that is, how many there are) So if the input were: hooligan sausage […]

Read More

Write the definition of a method named countPos that receives a reference to a Scanner object associated with a stream of input consisting of integers only.

1
Write the definition of a method named countPos that receives a reference  to a Scanner object associated with a stream of input consisting of integers only.

LANGUAGE: JAVA CHALLENGE: Write the definition of a method named countPos that receives a reference to a Scanner object associated with a stream of input consisting of integers only. The method reads all the integers remaining to be read in standard input and returns the number that are positive. So if the input were: 19 […]

Read More

Write the definition of a method named makeStarBucks that receives a non-negative integer n and returns a String consisting of n asterisks followed by n dollars signs.

Write the definition of a method named makeStarBucks that receives a non-negative integer n and returns a String  consisting of n asterisks followed by n dollars signs.

LANGUAGE: JAVA CHALLENGE: Write the definition of a method named makeStarBucks that receives a non-negative integer n and returns a String consisting of n asterisks followed by n dollars signs. So, if the method received 5 it would print: *****$$$$$ and if received 3 it would print ***$$$ The method must not use a loop […]

Read More

Write the definition of a method named copy receives a reference to a Scanner object associated with a stream of input.

1
Write the definition of a method  named  copy receives a reference  to a Scanner object  associated with a stream of input.

LANGUAGE: JAVA CHALLENGE: Write the definition of a method named copy receives a reference to a Scanner object associated with a stream of input. The method reads all the Strings remaining to be read from the stream and displays them, one on a line with no other spacing IN REVERSE ORDER, onto standard output. So […]

Read More

Write a recursive, void method , reverse, that accepts an integer array , a starting index and an ending index, and reverses the array.

1
Write a recursive, void method , reverse, that accepts an integer  array , a starting index and an ending index, and reverses the array.

LANGUAGE: JAVA CHALLENGE: Write a recursive, void method , reverse, that accepts an integer array, a starting index and an ending index, and reverses the array. Reversing an array involves: • Nothing if the array has 0 or 1 elements . • swapping the first and last elements of the array and then reversing the […]

Read More

Write a recursive, boolean -valued method named search that accepts an integer array , the number of elements in the array, and an integer (in that order), and returns whether the integer is present as an element in the array.

1
Write a recursive, boolean -valued  method named search that accepts an integer  array , the number of elements in the array, and an integer  (in that order), and returns whether the integer is present as an element in the array.

LANGUAGE: JAVA CHALLENGE: Write a recursive, boolean -valued method named search that accepts an integer array , the number of elements in the array, and an integer (in that order), and returns whether the integer is present as an element in the array. Searching for a particular value in an array can be performed in […]

Read More

Write a recursive, int -valued method named productOfOdds that accepts an integer array, and the number of elements in the array and returns the product of the odd-valued elements of the array.

Write a recursive, int -valued  method  named  productOfOdds that accepts an integer  array, and the number of elements  in the array  and returns the product  of the odd-valued  elements  of the array.

LANGUAGE: JAVA CHALLENGE: Write a recursive, int -valued method named productOfOdds that accepts an integer array, and the number of elements in the array and returns the product of the odd-valued elements of the array. You may assume the array has at least one odd-valued element . The product of the odd-valued elements of an […]

Read More