im creating a program that will convert certain character into its ascii value then i will change the value. for example the ascii value of A is 65 right? but i want to change the value of it into 1 so if i input A the output of it is 1. how am i supposed to do this? pls give some ideas. tnx

Recommended Answers

All 3 Replies

A Java char is, by definition, a numeric value that represents a character. So you can freely mix character representations such as 'a' or 'Z' and numeric expressions, eg

int i = 'C';        // i = 67
int j = 'C' - 'A';  // j = 2

if i do that then i must have many declarations to be used. im trying to do a very simple password encryption.

Basically you can convert the password string to an array of chars, and do your arithmetic on that in a simple loop - here's some pseudo-code to point you in the direction:
String pw = ... get the password
char[] ca = pw.toCharArray() // now you have the chars separated into the array
loop thru array adding/subtracting some value from each char
pw = new String(ca) // convert char arry back to a String

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.