hi everyone,
pls solve me the following problem.

i need a java program that stores the following string in a two-dimensional char array : "Bell" "Dell","Hell" and "Sell".extend the programe to read the array and display each caracter in a console window.

thank you.

shantuli

Dani AI

Generated

A simple, clear approach is to convert each Java String to a char[] and store those arrays in a two-dimensional (possibly ragged) char[][]. The example below creates a row per word and then walks the array with nested loops, printing each character and its coordinates so the console output is easy to follow.

public class TwoDCharArray {
    public static void main(String[] args) {
        String[] words = {"Bell", "Dell", "Hell", "Sell"};
        char[][] grid = new char[words.length][];
        for (int i = 0; i < words.length; i++) {
            grid[i] = words[i].toCharArray();
        }

        for (int r = 0; r < grid.length; r++) {
            for (int c = 0; c < grid[r].length; c++) {
                System.out.println("[" + r + "][" + c + "] = " + grid[r][c]);
            }
        }
    }
}

Notes and common variations: if every string is the same length you can use a rectangular char[rows][cols] and fill it directly; if lengths differ, a ragged char[][] (as shown) is simpler. You can print characters with System.out.print(grid[r][c]) to show rows as lines instead of individual labeled entries. Use String.toCharArray() or charAt() — both are fine; toCharArray() is convenient for copying.

A couple of cautions: Java char holds a UTF-16 code unit, so characters outside the basic multilingual plane require special handling (use code points if needed). Also prefer keeping data as String[] unless you need mutable character arrays. This post addresses 's request; earlier replies from , and were unhelpful and can be ignored — the sample above gives a practical, correct way to store and display each character.

Recommended Answers

All 3 Replies

>pls solve me the following problem.
No, do your own freaking homework you lazy bobo.

lazy bobo.

Thats a good one. I like that.

do u know somthing abt java
or using this forum for hw
.............................................

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.