• Post Reply Bookmark Topic Watch Topic
  • New Topic

Making One Thing Repeat, Until I Want It To Stop...  RSS feed

 
Greenhorn
Posts: 29
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So after a long, long, long, long, long... really long absence, I have finally found myself back to learning Java programming. So after reading up a bit and feeling comfortable to do a task, I tried this:

Purpose: To learn how to follow the style guide, how to get the argument from the command line, how to use variables, how to concatenate strings, how to use a loop effectively, and how to output to the screen (standard out). Write a program that will read in a name from the command line and write it out 100 times.
In other words, I want to type

java Hundred Gertrude


So, I pulled up npp (Notepad++) and wrote. But I can't get it to work. Again, complete noob here, but I need to know what I am missing. Did I not close the loop properly, because I am hitting an infinite loop after the 100 mark. Here is my code (I changed 100 to 10 until I can figure this out):



It is telling me,class, interface, or enum expected, but I am unable to determine which or where. Blah!

Please point me in a direction so that I can understand what I am doing wrong. I truly love you all, and thanks for helping me learn and become better!
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rodge Paroissiaux wrote:I am hitting an infinite loop after the 100 mark.

It is telling me,class, interface, or enum expected


Well the second message is a syntax error which means your code won't compile, but the first problem is a runtime error which means your code must have compiled.
So which are you having a problem with ?

For what it's worth, the code you posted compiled fine.
Take a look at your while loop. It keeps running until i is greater than 100, but you never change the value of i.
 
Sheriff
Posts: 11594
185
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you're not attaining the objective of knowing how to get an argument from the command line and printing it out 100 times. Instead, you're assigning a literal String value to a variable and doing nothing with it while ignoring the command line parameters altogether.
 
Rodge Paroissiaux
Greenhorn
Posts: 29
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joanne Neal wrote:

Rodge Paroissiaux wrote:I am hitting an infinite loop after the 100 mark.

It is telling me,class, interface, or enum expected


Well the second message is a syntax error which means your code won't compile, but the first problem is a runtime error which means your code must have compiled.
So which are you having a problem with ?

For what it's worth, the code you posted compiled fine.
Take a look at your while loop. It keeps running until i is greater than 100, but you never change the value of i.



Junilu Lacar wrote:And you're not attaining the objective of knowing how to get an argument from the command line and printing it out 100 times. Instead, you're assigning a literal String value to a variable and doing nothing with it while ignoring the command line parameters altogether.



I completely jacked up the i and I didn't even realize I somehow left out the i++ for the additional increase. Wow! Here is my corrected code, which npp is compiling and running fine:



Thank you, to you both!!!
 
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post CattleDrive solutions in the forums.... no spoilers!

Moving you to the correct topic, and getting rid of the code.
 
Rodge Paroissiaux
Greenhorn
Posts: 29
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Janeice DelVecchio wrote:Please don't post CattleDrive solutions in the forums.... no spoilers!

Moving you to the correct topic, and getting rid of the code.



I apologize. Thank you.
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No worries!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!