0
How to increment alphabet in a string
Ex :String a="abcdef"; Result: bcdefg
5 Antworten
+ 5
Sharuk Mohammad Can you pls show your attempt?
+ 2
Well just a hint
Chop characters increment them and store in another string
well I think it is the ans itself
😃😃
+ 1
Well I know the answer but what will I get in return
- 1
create a char array of your string with .toCharArray()
use a for loop to increment each char
String test = "abcdef";
char[] arr = test.toCharArray();
for(int i = 0; i < arr.length(); i++){
arr[i]++;
}
String result = String.valueOf(arr);
You can put this in a method where you return the result. And you need to think about 'z' and 'Z'.