A literal character is represented inside a pair of single quotes.
public class Main {
public static void main(String[] argv) {
char ch = 'a';
System.out.println("ch is " + ch);
}
}
The output generated by this program is shown here:
ch is a
All of the visible ASCII characters can be directly entered inside the quotes, such as 'a', 'z', and '@'.
public class Main {
public static void main(String[] argv) {
char ch = '@';
System.out.println("ch is " + ch);
ch = '#';
System.out.println("ch is " + ch);
ch = '$';
System.out.println("ch is " + ch);
ch = '%';
System.out.println("ch is " + ch);
}
}
The output generated by this program is shown here:
ch is @
ch is #
ch is $
ch is %
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |