Reputation: 2684
My task is to display specified text e.g. "dummy123". But the problem is that I can't use neither " nor ' and even no integers to do something like that. As I know in Java is no preprocessor like
#define W(x) #x;
How to have code like that without quotes:
public class A
{
public static void main(String[] args)
{
System.out.println("dummy123");
}
}
Upvotes: 2
Views: 4424
Reputation: 1979
Make an enum
public enum myEnum{
dummy123
}
Then use the .toString
public static void main(String [] args){
String x = Test.dummy123.toString();
System.out.println(x);
}
Output: dummy123
Upvotes: 6
Reputation: 178253
Determine what the Unicode codes are for each of the characters in the String
you want. Then create a char[]
and cast your numeric Unicode codes to char
to initialize your char[]
. E.g., 'd'
is (char) 100
. Then you can create a String
from the char[]
. This uses no double-quote or single-quote characters in the source code.
Upvotes: 3
Reputation: 2803
In java a char is interchangeable with an Int. You could just use a technique like:
System.out.print(Character.toChars(X));
Where X is the integer value of the character in question :D
See http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Character.html#toChars%28int%29 for more info.
Upvotes: 1