2

I have to write a Java program for cryptography which takes a number from the user and adds( or subtracts the number if it is negative) from the ASCII code of the character. For example if the number taken is 2, and the given string is "ABCZ" it should return "CDEB". I've figured out most of it, but I'm not sure how to return the character which has a given ASCII code. So if the ASCII is 65,how do I return "A"? I'm only in class 10,so please keep it as simple as possible. Thanks in advance.

aqua
  • 719
  • 4
  • 11
  • 17

1 Answers1

1

All you need is to cast the number to a character.

int yourInt = 65;
char ch = (char) yourInt;
System.out.println(yourInt);
System.out.println(ch);
// Output:
// 65
// A
Mike de Dood
  • 393
  • 1
  • 9