0

the user will enter a char and I have to implement the previous char then the given char then the previous char again for example: input: B output: ABA so how to get the previous char?

RaOm
  • 1
  • 1
  • Learn about the asciitable – Scary Wombat Oct 20 '22 at 01:50
  • 1
    Given your current definition it is unclear what the "previous char" of `A` would be – KompjoeFriek Oct 20 '22 at 01:55
  • In Java `char` is *numeric* type representing *index* of character in Unicode Table. So if you have `char ch = 'B';` you can cast it to `int` to see index of `A` via `int index = (int)ch;`. Also we can use mathematical operators on `char` like `+` `-` for instance `'A'+1`. BUT result of such calculation will be of type `int` not `char`, so you may need to cast that result back to `char` if you want to know what symbol is after it like `char afterB = (char)('B'+1);`. – Pshemo Oct 20 '22 at 02:01
  • Try executing `System.out.println((char)('B' - 1));` – Bohemian Oct 20 '22 at 02:27

0 Answers0