Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java file input  RSS feed

 
Jay Mize
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I modify this part of my code so that "token" would be the previous number the program input from the text file and the current number? For example, there is 2 number inside the text file, the 1st = 2 and the 2nd =4 , how can I make "token" be the sum of these two? Thanks


 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be += rather than =+.

With =+, you're just assigning the positive value of the number to the variable.
 
Jay Mize
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, thank you so much!
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That assumes token is a number. That is a very poor name for a number; I would think it is a String (still a poor name if you are applying += to it). If it is a String, the compiler will not permit =+ to be applied to it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!