1 Replies - 243 Views - Last Post: 22 February 2019 - 01:42 PM Rate Topic: -----

#1 sith   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 15-January 19

How to store the contents of string array to 2d char array

Posted 22 February 2019 - 12:52 PM

Hi,the following code asks for grid size and then takes the input values from the keyboard and stores contents in "str".Now I want to store contents of "str" in a 2-dimensional character array named char[][] board. How do I do that? Please be patient I am new to coding.

Scanner s = new Scanner(System.in);

System.out.println("Enter grid size");

       int t = s.nextInt(); // read number of elements
       s.nextLine(); // consume new line
     System.out.println("Enter the values");
     int d = s.nextInt(); // read number of elements
        s.nextLine();
         String str[] = new String[t];

        for(int k=0;k<t;k++)
        {
         str[k]=s.nextLine();
       }

Sample Output:
Enter grid size
3
Enter the values
123
234
456


Is This A Good Question/Topic? 0
  • +

Replies To: How to store the contents of string array to 2d char array

#2 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 834
  • View blog
  • Posts: 6,437
  • Joined: 25-December 13

Re: How to store the contents of string array to 2d char array

Posted 22 February 2019 - 01:42 PM

Quote

store contents of "str" in a 2-dimensional character array named char[][] board.

Can you give example Strings and the desired array contents?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1