syntax - Java controlf and escape sequences -
i'm trying skip line using escape sequence, code looks like
system.out.printf("number of students: " + numberofstudents "\n");
but getting error says "syntax error on token ""\n"", delete token"
i same error when trying
system.out.printf("number of students: %c", numberofstudents "\n");
this code works i'm trying understand did wrong
system.out.printf("number of students: %d \n", numberofstudents );
is there rule against using escape sequences after referencing variable?
thanks
this:
numberofstudents "\n"
isn't valid. you've got 2 tokens there - identifier , string literal - space between them. that's not valid. use concatenation:
system.out.printf("number of students: " + numberofstudents + "\n");
if want... can't put string literal @ end that.
i suggest final code cleanest anyway, although i'd remove space before line break. alternative let println
put line break on you:
system.out.println("number of students: " + numberofstudents);
Comments
Post a Comment