Create a word from the letters at the index passed from the multiple words(2d char array). The words length might be different.
Input(2D char array), index |
Output(char array) |
{ { 'C', 'h', 'i', 'r', 'a', 'n', 'j', 'e', 'e', 'v', 'i'}, { 'V', 'e', 'n', 'k', 'a', 't', 'e', 's', 'h'}, { 'P', 'r', 'a', 'b', 'h', 'a', 's' }, { 'M', 'o', 'h', 'a', 'n', 'B', 'a', 'b', 'u' } } , 1 |
{'h', 'e', 'r', 'o'} |
{ { 'S', 'o', 'f', 't', 'w', 'a', 'r', 'e' }, { 'E', 'n', 'g', 'i', 'n', 'e', 'e', 'r' } }, 0 |
{'S', 'E'} |
{ {'M', 'a', 'n', 'g', 'o'}, {'S', 'a', 'p', 'o', 'd', 'i', 'l', 'l', 'a'}, {'B', 'a', 'n', 'a', 'n', 'a'} }, 3 |
{'g', 'o', 'a'} |
class CreateWordFromIndexLetters
{
public static void main(String s[])
{
char multipleWords[][] = {
{ 'C', 'h', 'i', 'r', 'a', 'n', 'j', 'e', 'e', 'v', 'i'},
{ 'V', 'e', 'n', 'k', 'a', 't', 'e', 's', 'h'},
{ 'P', 'r', 'a', 'b', 'h', 'a', 's' },
{ 'M', 'o', 'h', 'a', 'n', 'B', 'a', 'b', 'u' }
};
char word[] = createWord(multipleWords, 1);
System.out.print("The word is ");
for(char ch : word)
System.out.print(ch + "");
}
public static char[] createWord(char [][]words, int index)
{
}
}
Topic:
Learn Arrays And Loops
If you need explanation Read this topic
If you need Answer Take test on this topic
User comments below. All of them might not be correct.
here we need to take the char of the specified index in every row so we need to travel through the each row
*length of the word=num of rows in the array
*create an array with the length of the 2D array means num of rows
*for loop to travel through the array
* output[i]=words[i][index];
after coming out of the loop return array
Posted by Uday Kumar 2015-03-04 05:45:12
To form the characwr array from the given 2D array we have to use FOR loop.
For loop runs till the length of 2D array.
--we have to declare one character array to store he resultant character in it.
--After that inside for loop we have to assign word [counter][index] to result[counter].
--At the end of function we have to return the result character array.
Posted by Mânïshå Mùlchåndânï 2015-03-04 07:59:08
here we have to create the words from the lettr at the index pased from the multiple word.... an index is gvn. and ee hve to extrct charctr at this imdx frm every row.... length of the wrd= no. of rows in 2d array..... now take a loop a=0 to rows.... output[a]=word[a][index] ....end loop..... print output
Posted by Asma Mujtaba Khan 2015-03-04 08:08:02
This dose is now closed and the winners are Uday Kumar, for 'First Correct Comment', Mânïshå Mùlchåndânï, Asma Mujtaba Khan, for 'Second Correct Comment'. The 'lucky liker' is Shashanka Mogaliraju. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.
Posted by Merit Campus 2015-03-05 01:36:39