+ 1

convert the characters of a string into its respective sequential alphabetic number

Eg: String str="Hey you"; output: str = 8 5 24 24 15 21 This is the code i've tried and i guess this code might be quite complex.But still am a newbie this is something that i could do at its extreme. And now coming to the point, i need a statement that swaps the value of character of the given string into the respective number 'j' as you see in the program. note: got to work at line number 18. ArrayList<Character> alp=new ArrayList<>(); char x='a'; for(x='a';x<='z';x++) { alp.add(x); } String y="Hi there dood"; String z=y.toLowerCase(); int i,j; for(i=0;i<26;i++) { int m=z.charAt(0); int n; n=m-'a'+1; System.out.println(n); for(j=1;j<=26;j++) { if(n==j) { int k='j'; char c=(char)k; z.charAt(i)='c'; }

8th Dec 2018, 3:15 PM
So What!!
So What!! - avatar
5 Respuestas
+ 16
● In 18th line : String in java are immutable , so z.charAt(i) = 'c' will not work & give error . ● need of statement to change character to ASCII value (in int) //2 ways : 1) int ascii =(int) ch; 2) int ascii = ch; ● now lets come to problem solving part [I just thought] 0)make string to lower case 1)make String to char array 2)run a loop over array printing [(ASCII value of each character) - 96] except spaces . edit : see Rstar code , easy way just like mine of solving it [without even using char array ]☺
8th Dec 2018, 3:50 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
Gaurav Agrawal oops yeh ur right...so tis complete code is gonna be a mess or wat??? Or is there anyother alternatives in sequel with this code..
8th Dec 2018, 3:54 PM
So What!!
So What!! - avatar
+ 2
Rstar tanx dood
8th Dec 2018, 3:58 PM
So What!!
So What!! - avatar
+ 2
Gaurav Agrawal chill of u...tanx
8th Dec 2018, 4:00 PM
So What!!
So What!! - avatar