Question

Write a method, strToArr, which takes one argument, aString , and returns a character array that...

Write a method, strToArr, which takes one argument, aString , and returns a character array that represents the String. For example,

strToArr("hi") should return {'h', 'i' }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class MyClass {
public static char[] strToArr(String str)
{
return str.toCharArray(); //to convert string to array of characters
}
public static void main(String args[]) {
String name="Joe Carter";
  
System.out.println("String Form is: "+name);
char[] charName=MyClass.strToArr(name); //converting string to array of characters
System.out.print("Char Array Form is: ");
for(int i=0;i<charName.length;i++)
{
System.out.print(charName[i]);
}
  
  
}
}

___________________OUTPUT______________________

String Form is: Joe Carter Char Array Form is: Joe Carter

Add a comment
Know the answer?
Add Answer to:
Write a method, strToArr, which takes one argument, aString , and returns a character array that...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. Write a method buildString which takes a 2D array of characters (char), and returns a...

    3. Write a method buildString which takes a 2D array of characters (char), and returns a string that is built from all the characters in that array. For example, the following method call should return "hello!" buildString( new char[] [ 'h', 'e',

  • package week_3; /** Write a method called countUppercase that takes a String array argument. You can...

    package week_3; /** Write a method called countUppercase that takes a String array argument. You can assume that every element in the array is a one-letter String, for example String[] test = { "a", "B", "c", "D", "e"}; This method will count the number of uppercase letters from the set A through Z in the array, and return that number. So for the example array above, your method will return 2. You will need to use some Java library methods....

  • Write a function called smallestLetter that takes in a string argument and returns a char. The...

    Write a function called smallestLetter that takes in a string argument and returns a char. The char that is returned by this function is the character in the string with the lowest ASCII integer code. For example: smallestLetter("Hello") returns ‘H’ which is code 72, and smallestLetter("Hello World") returns ‘ ’ (The space character) which is code 32

  • Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...

    Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...

  • Write a cell method that takes a single double as an argument and returns an int....

    Write a cell method that takes a single double as an argument and returns an int. The int should be the next highest whole integer (eg 3.14 would return 4). Use math not built-in Java methods mins) Write a method that takes a string as an argument. It your string is more than 10 letters or less than 1 letter return "Bad number". Otherwise, return the telephone number equivalent of the input. Your return can be of type String Eg...

  • Write a ceil method that takes a single double as an argument and returns an int....

    Write a ceil method that takes a single double as an argument and returns an int. The int should be the next highest whole integer (eg 3.14 would return 4). Use math, not built-in Java methods (est. 20 mins) Write a method that takes a string as an argument. If your string is more than 10 letters or less than 1 letter return "Bad number." Otherwise, return the telephone number equivalent of the input. Your return can be of type...

  • write a function which takes a string argument and a character argument. It should return a...

    write a function which takes a string argument and a character argument. It should return a truth value (int 0 or 1), 0 if the string does not contain the character, and 1 if the string does contain the character. Do not use a built-in library for this. Again, call this function and its variables whatever you deem appropriate. The main function of the program should accept a single character followed by Enter. Then, it will read lines until the...

  • RUBY! \Write a method called reverse_each_word that takes in a string argument of a sentence and...

    RUBY! \Write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sentence with each word reversed in place. First solve it using .each Then utilize the same method using .collect to see the difference. For example: reverse_each_word("Hello there, and how are you?") #=> "olleH ,ereht dna woh era ?uoy" Hint: You can't use an enumerator on a string, so how can we turn our string into an array? Hint: How can we...

  • MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the...

    MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the longest string and largest number in arr. If there are two character arrays of same length, the function should return one of them. Assume that integers in the cell array are nonnegative.

  • 11) Write a method (including header and body) that takes as an input an array of...

    11) Write a method (including header and body) that takes as an input an array of doubles and f three doubles containing the average, the maximum and the minimunm values of the input array. Test the program by calling the method from the main method. For example Input: 1 2 3 45 Output: 3 5 1 12) Write a Java method that takes a string as an argument and returns the reverse the string. Test the program by calling the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT