how to convert string to int in Java -
this question has answer here:
- how convert string int in java? 28 answers
- how convert int string? 18 answers
i'm working on caesar cipher example in want different keys user , 1 key decrypt original text , got problem, here code
public static void main(string[] args) { scanner user_input= new scanner(system.in); string plaintext = "university of malakand"; string key; key = user_input.next(); ceasercipher cc = new ceasercipher(); string ciphertext = cc.encrypt(plaintext,key); system.out.println("your plain text :" + plaintext); system.out.println("your cipher text :" + ciphertext); string cplaintext = cc.decrypt(ciphertext,key); system.out.println("your plain text :" + cplaintext); }
it shows error on line
string ciphertext = cc.encrypt(plaintext,key);
it shows me error on key incompatible types:
string cannot converted int
what can do?
ask following questions self first.
- what method want parameter?
- why both incompatible?
- what
string ciphertext = cc.encrypt(plaintext,key);
mean? - key
string
orint
?
use methods integer.parseint(string value)
or integer.valueof(string value)
conversion.
Comments
Post a Comment