Presentation is loading. Please wait.

Presentation is loading. Please wait.

Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is.

Similar presentations


Presentation on theme: "Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is."— Presentation transcript:

1 Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is upper case.”); } else if (isLowerCase(c)) { System.out.println(c + “ is lower case.”); } else { System.out.println(c + “ is not in English alphabet.”); } }// continued in next slide

2 Checking character case public static boolean isUpperCase (char c) { return (isBetween(‘A’, c, ‘Z’)); } public static boolean isLowerCase (char c) { return (isBetween(‘a’, c, ‘z’)); } // continued in next slide

3 Checking character case public static boolean isBetween (char a, char b, char c) { return ((a <= b) && (b <= c)); } } // end class

4 Case conversion class convertCase { public static void main (String arg[]) { char c = ‘M’; System.out.println(“Original: ” + c); if (isBetween(‘A’, c, ‘Z’)) { System.out.println(“After conversion: ” + toLower(c)); } else if (isBetween(‘a’, c, ‘z’)) { System.out.println(“After conversion: ” + toUpper(c)); } else { System.out.println(“Cannot convert case!”); } } // continued in the next slide

5 Case conversion public static boolean isBetween (char a, char b, char c) { return ((a <= b) && (b <= c)); } public static char toLower (char c) { return (c – ‘A’ + ‘a’); } public static char toUpper (char c) { return (c – ‘a’ + ‘A’); } } // end class

6 Local variable example class local { public static void change1(int n){ n=5; } public static int change2(int n){ n=5; return n; } public static void main (String args[]) { int n = 0; int x = 0; change1(n); System.out.println("n="+n); x = change2(n); System.out.println("n="+n+" and x="+x); }


Download ppt "Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is."

Similar presentations


Ads by Google