An interesting problem about char[][]
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Adi2000_Sharma
Posted On:   Wednesday, June 30, 2004 08:17 AM

Hi experts, Can anyone tell me a method by which i could store a char[][] in a string. This is the actual problem public class Problem { public static void main(String args[]) { char a[][]; char b[][]; a=new char[12][20]; b=new char[12][20]; a[1][0]='a'; a[1][1]='b'; a[1][2]='c'; System.out.println(a[1]); //Now a[1] behaves as String displaying abc //Now i want to store this variable a[1] in an actual //string variable say str //How can i do it ? } } Kindly do not sugge   More>>

Hi experts,

Can anyone tell me a method by which i could store a

char[][] in a string.


This is the actual problem


public class Problem

{

public static void main(String args[])

{

char a[][];

char b[][];

a=new char[12][20];

b=new char[12][20];

a[1][0]='a';

a[1][1]='b';

a[1][2]='c';

System.out.println(a[1]);

//Now a[1] behaves as String displaying abc

//Now i want to store this variable a[1] in an actual

//string variable say str

//How can i do it ?

}

}


Kindly do not suggest (String) or toString().Tried both of them.

   <<Less

Re: An interesting problem about char[][]

Posted By:   Partha_sarathi  
Posted On:   Tuesday, July 20, 2004 04:13 AM

public class Problem
{
public static void main(String args[])
{
char a[][];
a=new char[12][20];

Character c;
String s1;

a[1][0]='a';
a[1][1]='b';
a[1][2]='c';

c=new Character(a[1][0]);
s1=c.toString();

c=new Character(a[1][1]);
s1=s1 + c.toString();

c=new Character(a[1][2]);
s1=s1 + c.toString();


System.out.println(a[1]);
System.out.println(s1);

//Here s1 is the resultant string
}
}

Re: An interesting problem about char[][]

Posted By:   tech_tech  
Posted On:   Wednesday, June 30, 2004 02:52 PM

when u print System.out.println(a[1]); its is not actually printing a string. Try to do it on an IDE or something which is not a console. It actually prints the whole single dimensional array. so it looks like abc but it has a whole bunch of special characters after that . so its actually not a string as u may htin thry the system.out statement. try changing ur logic.

Re: An interesting problem about char[][]

Posted By:   Trent_Andrews  
Posted On:   Wednesday, June 30, 2004 10:45 AM

I believe you can do the following

String str = String.valueOf(a[1]);
About | Sitemap | Contact