Question

Java Lab Assignment Write a method called convertToString. The method will take an array of chars...

Java Lab Assignment

Write a method called convertToString. The method will take an array of chars as an argument and it will return a String. Each index of the array will be part of the each index of the String.

method must be well documented using JavaDoc, example:

/** * The find method checks if the target in the array

* @param String [] a - array of Strings

* @param String t - value to be searched for

* @return true if the String t is found, false otherwise

*/

Homework Answers

Answer #1
//TestCode.java
public class TestCode {
    static String convertToString(char arr[]){
        String result = "";
        for(int i = 0;i<arr.length;i++){
            result += arr[i];
        }
        return result;
    }
    
    public static void main(String[] args) {
        char arr[] = {'h','e','l','l','o'};
        System.out.println(convertToString(arr));
    }
}

hello

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java Lab Assignment Write a method called convertToArray. The method will take a String as an...
Java Lab Assignment Write a method called convertToArray. The method will take a String as an argument and it will return an array of chars. Each index of the String will be stored in each index of the array. method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for * @return...
Java Lab Assignment Write a method named findMax. The method will take an array of doubles...
Java Lab Assignment Write a method named findMax. The method will take an array of doubles as an argument, and it will return the largest value in the array. (Note, you will have to create a new array of doubles) . method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for...
Write a template function maxn() that takes as its arguments an array of items of type...
Write a template function maxn() that takes as its arguments an array of items of type T and an integer representing the number of elements in the array and that returns the largest item in the array. The number of elements should take the default value of 10. The program should include a specialization that takes an array of strings as an argument and returns the longest string. (If there is a tie, the function should return the first one...
THIS IS JAVA PROGRAMMING Write a method that finds the shortest word in an array of...
THIS IS JAVA PROGRAMMING Write a method that finds the shortest word in an array of String values and returns the length, in characters, of that word. The method should use the following header. public static int minLength(String[] array) Write a test program that prompts the user to enter ten strings, store them in an array and invokes this method to return the shortest length, and displays that value. (A near complete program can be found attached to the dropbox)
Java Write a method that uses an ArrayList and its contains method to take an input...
Java Write a method that uses an ArrayList and its contains method to take an input array of strings return a new array, free of any duplicate strings.
-Previously - java class with one static method. In the static method called beforeThis. take 2...
-Previously - java class with one static method. In the static method called beforeThis. take 2 strings as inputs and return a string. Code for the method should look for 1st input String within the 2nd input, and return everything from 2nd input string that comes before. ex: 1st input : "tennis" 2nd input : "A tabletennis is in the basement" method returns: "A table"
IN JAVA: Write recursive method to return true if a given array has element equal to...
IN JAVA: Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp,...
Java programming. Write a public Java class called WriteToFile that opens a file called words.dat which...
Java programming. Write a public Java class called WriteToFile that opens a file called words.dat which is empty. Your program should read a String array called words and write each word onto a new line in the file. Your method should include an appropriate throws clause and should be defined within a class called TextFileEditor. The string should contain the following words: {“the”, “quick”, “brown”, “fox”}
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
Write a method that take in an array of integers, find the maximum and minimum, and...
Write a method that take in an array of integers, find the maximum and minimum, and return an array containing four elements in the following order. max integer, max integer index, min integer, min integer index