javascript
Brief description  about Online courses   join in Online courses
View shalini shalu vellaluri 's Profile

multidimensional array

2. Write a program to demonstrate multidimensional array in which you have to use a character instead of numbers.
The output should be something like:
A B C D
E F G H
I J K L
M N O P
solution:
class arraye {
public static void main(String[] args) {
char[][] TwoDarray = new char[5][5];
for (int i='A'; i<TwoDarray.length; i ) {
for (int j='A'; j<TwoDarray[i].length; j ) {
TwoDarray[i][j] = i;
System.out.print(" " TwoDarray[i][j]);
}
System.out.println("");
}
}
}
15.217/arraye.java:6: error: incompatible types: possible lossy conversion from int to char
TwoDarray[i][j] = i;
^
1 error
how to solve the code ffor above given program
Asked by shalini shalu vellaluri | Jun 19, 2017 |  Reply now
Replies (1)
View Anjali Chitravel 's Profile
hi, in for loop you are declaring char that's why you are getting such error instead use i=0 and you are not incrementing i and j in for loop
Jun 20, 2017