Can anyone tell me why I am getting unusual output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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)); } }

16th Jan 2021, 10:38 AM
Atul [Inactive]
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
16th Jan 2021, 11:56 AM
zemiak
+ 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 );
16th Jan 2021, 12:20 PM
zemiak
0
Can we done something so that o and g will be printed. Without using strings or writing there ASCII values?
16th Jan 2021, 12:00 PM
Atul [Inactive]
0
Thank you
16th Jan 2021, 2:11 PM
Atul [Inactive]