0

How to increment alphabet in a string

Ex :String a="abcdef"; Result: bcdefg

9th Jul 2020, 1:04 PM
Sharooq Mohammad
4 odpowiedzi
+ 5
Sharuk Mohammad Can you pls show your attempt?
9th Jul 2020, 1:07 PM
Nilesh
Nilesh - avatar
+ 2
Well just a hint Chop characters increment them and store in another string well I think it is the ans itself 😃😃
9th Jul 2020, 1:16 PM
MST
+ 1
Well I know the answer but what will I get in return
9th Jul 2020, 1:15 PM
MST
- 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'.
10th Jul 2020, 9:02 PM
Denise Roßberg
Denise Roßberg - avatar