|
hi all;
i have a probelm to append character become a string. for instance:
char first, second, third;
String theword;
for(char r = 'a'; r <= 'z'; r++){
first = r;
for(char s = 'a'; s<='z'; s++){
second = s;
for (char t = 'a'; t <= 'z'; t++){
third = t;
theword = first + second + third;
}
}
}
I want to print 'first + second + third' but i have problem to convert char into string. how actually can i convert char to string or it is possible for me to convert it? does any can give some hints or give me a related website so that can refer to it?
i really appreaciate anyone's help! thanx in advance!
regards;
dulcinea
|
|
|
The problem with your code was that the character variables were not initialized. All i did was set each of them to the character 'a'.
You can concatenate characters to strings without a method.
Use "java docs" they are quite helpful when it comes to finding a method that meets your requirements.
public class Concat{
public static void main(String arg[]){
char first='a', second='a', third='a';
String theword;
for(char r = 'a'; r <= 'z'; r++)
first = r;
for(char s = 'a'; s<='z'; s++)
second = s;
for (char t = 'a'; t <= 'z'; t++)
third = t;
theword = ""+first + second + third;
System.out.println(theword);
}
} //end of class
|
|
|
public class Test
{
public static void main(String[] args)
{
char first, second, third;
String theword;
for(char r = 'a'; r <= 'b'; r++){
first = r;
for(char s = 'a'; s <= 'b'; s++){
second = s;
for (char t = 'a'; t <= 'b'; t++){
third = t;
theword = String.valueOf(first) + second + third;
System.out.println(theword);
}
}
}
}
}
|
|
|
|
|
thnx.. i really appreciate your help! it works!
thank you very much!
regards;
nurul
|
|
|
|
|
|
|
|