I need to convert a set of chars into a string. The problem is, I don't know how to do it without an array (it's forbidden to use them, because we didn't see the this subject yet).
So the method starts with asking the user to type in a word (String type). In this case I use the word "programma" as an example. The first step is too count +4 to every character of that word. In this example it must change from "programma" --> "tvskveqqe".
I split up the input string "programma", into seperate chars, and added +4 in the alfabet. Afterwards I made sure if the letters "wxyz" are used, that they are converted to w --> a, x -->b, y --> c and z --> d.
But now I'm stuck at the part, where I need to put the chars 't''v''s''k''v''e''q''q''e' into a string "tvskveqqe", and use that as return statement.
Thanks!
public char coderen() {
String str; //input string
char c, e = ' ';
int a = 4, b, d;
System.out.println("Geef een woord in: ");
str = Input.readString(); //input
for (int i = 0; i < str.length(); i++) { // Splits up the string into separate chars
b = (int) str.charAt(i) + a; // +4 in ASCII
c = (char) b;
if (c >= 'e' && c <= 'z') {
e = c;
System.out.println(e);
}
else if (c >= '{' && c <= '~') { // converts 'w''x''y''z' into 'a''b''c''d'
d = (int)c - 26;
e = (char) d;
System.out.println(e);
}
else {
System.out.println("fout!");
}
}
return e;
}