Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Java 2d Character array

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java 2d Character array

    for(int i=0;i<c1+1;i++)
    {
    for(int j=0;j<3;j++)
    {
    System.out.print(ascii[i][j]);

    }
    // System.out.println();
    }

    System.out.println();

    int digit[] = new int[c.length];


    for(int i=0;i<c1+1;i++)
    {
    for(int j=0;j<ascii[i].length;j++)
    {

    digit[i] = Integer.parseInt(String.valueOf(ascii[i][j]));
    }
    }

    for(int i=0;i<digit.length;i++)
    {
    System.out.print(digit[i]);

    }


    My question is that
    1. First I want to convert 2d character array contain number into 2d intger array. for eg. "8" -> 8
    2. Then want to make row of each 2d int array into string. 8 5 -> "85"
    3. Then convert string into character array. "85" -> U

    Problem with my code:
    1. Not able to convert the 2d character array into the 2d integer array.
    Last edited by Shrutika; December 3rd, 2020 at 01:52 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java 2d Character array

    convert 2d character array contain number and into 2d intger array.
    Can you explain what the conversion would do to a char to make an int? For example: 'A' > 1, 'B' > 2, etc

    make row of each 2d int array into string
    What would that conversion look like? For example: {123, 345} > "123345"

    convert it into character array.
    What is the "it"? The String class has a method to convert a String

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java 2d Character array

    1. First I want to convert 2d character array contain number into 2d intger array. for eg. "8" -> 8
    2. Then want to make row of each 2d int array into string. 8 5 -> "85"
    3. Then convert string into character array. "85" -> U

  4. #4
    Junior Member
    Join Date
    Dec 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java 2d Character array

    Here I share code whatever I used and know maybe work:

    Multidimensional Arrays can be defined in simple words as an array of arrays. Data in multidimensional arrays are stored in tabular form (in row-major order).

    Syntax:

    data_type[1st dimension][2nd dimension][]..[Nth dimension] array_name = new data_type[size1][size2].[sizeN];

    where:

    data_type: Type of data to be stored in the array. For example int, char, etc.
    dimension: The dimension of the array created.
    For example: 1D, 2D, etc.
    array_name: Name of the array
    size1, size2, , sizeN: Sizes of the dimensions respectively.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java 2d Character array

    "8" -> 8
    Look at the Integer class. It has a method to convert a String to an int

    make row of each 2d int array into string. 8 5 -> "85"
    Look at the Integer class for a method to convert an int to a String then use the String concatenation operator + to concatenate the Strings into a single String

    convert string into character array. "85" -> U
    Use the Integer class to convert the String into a int and then cast the int to a char: (char)85 is 'U'
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Dec 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java 2d Character array

    it doesnt work

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java 2d Character array

    it doesnt work
    Please explain. Post the code wrapped in code tags and any error messages you get.
    Also post any print outs that show what the code does.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Reading text file character by character into a 2d char[][] array
    By filipasa in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 18th, 2019, 07:09 PM
  2. Replies: 1
    Last Post: February 22nd, 2019, 03:10 PM
  3. Character Array
    By Mahmudul Hasan in forum What's Wrong With My Code?
    Replies: 9
    Last Post: July 17th, 2014, 06:08 AM
  4. Character Array
    By p_dibb in forum Collections and Generics
    Replies: 1
    Last Post: February 16th, 2011, 10:08 AM