java - can i use an if statement to append to a string? -
right have following code, , i'm trying code append string instead of system.out.println. know worded oddly, not sure how put it.
char[] c = inputstring.tochararray(); for(char ch : c) { if(ch <=88 && ch>=65 || ch<=120 && ch>=97) system.out.print(character.valueof((char) (ch+2))); else if (ch =< 1) system.out.print(character.valueof((char) (ch-24))); else if (ch == 2) system.out.print(character.valueof((char) (ch-24))); else system.out.print(ch);
all need defining string next c[] array
and add characters operator +=
, @ end have complete string of want,
char[] c = inputstring.tochararray(); string str = ""; for(char ch : c) { if(ch <=88 && ch>=65 || ch<=120 && ch>=97) { str += character.valueof((char) (ch+2)); } else{ if (ch =< 1){ str += character.valueof((char) (ch-24)); }else { if (ch == 2){ str += character.valueof((char) (ch-24)); }else{ str += ch; } } } } // str result want can operation on wish
Comments
Post a Comment