java - What happens in system.out.print with empty quotations marks and no String assignment? -


i'm reading "head first java". code below 1 of exercises. idea figure out possible output.

there's 1 thing don't understand however.

within system.out.print couple of empty quotations used thought quotations used strings , in code example below there no strings? doing here, how should read it?

class test {     public static void main(string[] args) {         int x = 0;         int y = 0;         while ( x < 5 ) {             y = x - y;             system.out.println(x + "" + y + " " );             x = x + 1;          }     } }   

i can't sure of idea of guy whi make course, + "" + can avoid addition of 2 ints, in fact if concatenate instead of addition 2 ints :

system.out.println(x + "" + y + " " ); 

for example :

  • x + "" + y : going print 00 11 21 32 42 (with new lines of course between each)

  • x + y : going print 0 2 3 5 6 (with new lines of course between each)


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -