Lower/upper cases and ASCII codes of characters - Java Language Basics

Java examples for Language Basics:char

Description

Lower/upper cases and ASCII codes of characters

Demo Code

public class Main {

  public static void main(String[] args) {
    char c1, c2;/*from  ww  w.j a v  a  2  s .c om*/
    c1 = 'a';
    c2 = 'z';
    // Compare character code
    if (c1 < c2) {
      System.out.println(c1 + " is before " + c2);
    } else {
      System.out.println(c1 + " is after or equal to " + c2);
    }
    int codec1 = c1; // type casting/conversion
    int codec2 = c2; // type casting conversion
    System.out.println("Code ASCII for " + c1 + ":" + codec1);
    System.out.println("Code ASCII for " + c2 + ":" + codec2);
  }
}

Result


Related Tutorials