+ 2
Can anyone tell me why I am getting unusual output?
public class Program { public static void main(String[] args) { String n="go there "; for(int i=0;i<n.length()-3;i++){ char c=n.charAt(i+1); if(n.charAt(i+2)==' ') System.out.print(c+n.charAt(0)); } }
4 Answers
+ 1
There is lost } at the end, then
01234567
go there
i=0
c='o'
If space at 2
print 'o' + 'g' in ascii codes 103 + 111 = 214
+ 1
Usually this
System.out.print( "" +c +n.charAt(0) );
but strictly without String
System.out.append('o').append('g');
char[] ch = {'o', 'g'};
System.out.print( ch );
0
Can we done something so that o and g will be printed. Without using strings or writing there ASCII values?
0
Thank you