ASCII and Additional Char Methods Try this does

  • Slides: 18
Download presentation
ASCII and Additional Char Methods

ASCII and Additional Char Methods

Try this, does this work? String string. Test=“A”; char ch = string. Test; OR

Try this, does this work? String string. Test=“A”; char ch = string. Test; OR try it this way char ch = “A”;

Does this work char. Test=‘A’; String x = char. Test; OR String x =

Does this work char. Test=‘A’; String x = char. Test; OR String x = ‘A’;

Try this, does this work int x = 1; char ch = ‘A’; int

Try this, does this work int x = 1; char ch = ‘A’; int y = x + ch; System. out. println(y); OR int z = ch;

So then can we do this? int j = 15; char ch = j;

So then can we do this? int j = 15; char ch = j;

Yes we can char ch = (char)j;

Yes we can char ch = (char)j;

ASCII (see ASCII Table file for full table) Character ASCII 0 1 2 3

ASCII (see ASCII Table file for full table) Character ASCII 0 1 2 3 … 8 9 48 49 50 51 … 56 57 A B C D … Y Z 65 66 67 68 … 89 90 a b c d … y z 97 98 99 100 … 121 122

Convert between Strings and chars Conversion of a String into a character String s

Convert between Strings and chars Conversion of a String into a character String s = “C”; char a = s. char. At(0); //a now equals ‘C’ Conversion of a character into a String char a = ‘C’; String s = “” + a;

Conversion from capital to small Add 32 char upper. Case = ‘P’; char lower.

Conversion from capital to small Add 32 char upper. Case = ‘P’; char lower. Case = (char)(upper. Case + 32). System. out. println(lower. Case);

Boolean Methods “are you a digit? ” char ch = ‘a’; System. out. println(

Boolean Methods “are you a digit? ” char ch = ‘a’; System. out. println( Character. is. Digit(ch) ); char ch = ‘ 1’; System. out. println( Character. is. Digit(ch) );

Are you a letter? char ch = ‘a’; System. out. println( Character. is. Letter(ch)

Are you a letter? char ch = ‘a’; System. out. println( Character. is. Letter(ch) ); char ch = ‘ 1’; System. out. println(Character. is. Letter(ch) );

Are you a letter or Digit? char ch = ‘a’; System. out. println( Character.

Are you a letter or Digit? char ch = ‘a’; System. out. println( Character. is. Letter. Or. Digit(ch) ); char ch = ‘ 1’; System. out. println( Character. is. Letter. Or. Digit(ch) );

Are you a whitespace? char ch = ‘ ’; System. out. println( Character. is.

Are you a whitespace? char ch = ‘ ’; System. out. println( Character. is. Whitespace(ch) ); char ch = ‘a’; System. out. println( Character. is. Whitespace(ch) );

Are you a lowercase? char ch = ‘a’; System. out. println( Character. is. Lower.

Are you a lowercase? char ch = ‘a’; System. out. println( Character. is. Lower. Case(ch) ); char ch = ‘A’; System. out. println(Character. is. Lower. Case(ch) );

Are you an uppercase? char ch = ‘a’; System. out. println( Character. is. Upper.

Are you an uppercase? char ch = ‘a’; System. out. println( Character. is. Upper. Case(ch) ); char ch = ‘A’; System. out. println( Character. is. Upper. Case(ch) );

Other Non-Boolean Methods char ch = ‘a’; char nn = Character. to. Upper. Case(ch);

Other Non-Boolean Methods char ch = ‘a’; char nn = Character. to. Upper. Case(ch); System. out. println(nn);

Conversion to a lowercase char ch = ‘A’; char nn = Character. to. Lower.

Conversion to a lowercase char ch = ‘A’; char nn = Character. to. Lower. Case(ch); System. out. println(nn);

Homework Exercises for Lesson 13 Project: ASCII Quiz Game

Homework Exercises for Lesson 13 Project: ASCII Quiz Game