| Author |
when i run my virtual machine just keeps going, but no output.
|
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
does anyone know what my problem is?/how to fix it?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
when i run my virtual machine just keeps going, but no output.
Well, to have output, you actually need to generate output. Your code doesn't seem to do that. In fact, it doesn't even prompt the user when taking input -- it just fetches the input.
My guess is that your program is stuck waiting for more input from the user...
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Your problem is that you don't have enough lines of code which produce output. Add some more of them and you'll be able to see what your program is doing and thus figure out how to change it. Example of code you should add:
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
it still does it
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
As already mentioned... My guess is that your program is stuck waiting for more input from the user. You have an infinite loop waiting for input.
Or are you now saying that you removed all that stuff?
Henry
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
Henry Wong wrote:As already mentioned... My guess is that your program is stuck waiting for more input from the user. You have an infinite loop waiting for input.
Or are you now saying that you removed all that stuff?
Henry
it doesnt ask for user input, does it? if it does please point out my error.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Can you post the complete code? I can't tell what you are doing.
[EDIT: never mind. can you post the complete code? I am totally confused at the moment.]
Henry
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
Henry Wong wrote:Can you post the complete code? I can't tell what you are doing.
[EDIT: never mind. can you post the complete code? I am totally confused at the moment.]
Henry
i changed it to == and it still did the same thing. do you know anything else it could be?
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
Henry Wong wrote:Can you post the complete code? I can't tell what you are doing.
[EDIT: never mind. can you post the complete code? I am totally confused at the moment.]
Henry
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
nathan gibson wrote:
it doesnt ask for user input, does it? if it does please point out my error.
I knew I wasn't going crazy. I swore I saw it... it asks for user input here...
The "in" variable is a scanner object that is reading from System.in, hence, the code is waiting here for the user to type in an integer.
Henry
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
|
haha. alright, i know this is a noob question, but what do i change it to?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
nathan gibson wrote:haha. alright, i know this is a noob question, but what do i change it to?
It's your program. If you don't know what is it supposed to do, how do you expect us to know?
Henry
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
Henry Wong wrote:
nathan gibson wrote:haha. alright, i know this is a noob question, but what do i change it to?
It's your program. If you don't know what is it supposed to do, how do you expect us to know?
Henry
im sorry, its just im very close to finishing this. i have been working on it for days. thank you for your patience.
i have updated my code to this:
it will run now, but i cant get my output to work correctly. i think my problem is that i dont know how to calculate the sum of the numbers, can you show me?
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
i got it this far. now it is def the way i am doing my sum. i get a number for sum, just not correct.
|
 |
Janeice DelVecchio
Saloon Keeper
Joined: Sep 14, 2009
Posts: 1611
|
|
while (inFile.hasNextInt())
{
data = inFile.next( );
num = inFile.nextInt ();
// try putting a System.out.println(num); here
sum = + num;
// and a System.out.println(sum + " " + num); here......... this way you might be able to see why it's not coming out right......
}
My $0.02,
Janeice
|
When you do things right, people won't be sure you've done anything at all.
|
 |
nathan gibson
Ranch Hand
Joined: Sep 16, 2009
Posts: 120
|
|
|
lol += is what i needed. i found it out.
|
 |
 |
|
|
subject: when i run my virtual machine just keeps going, but no output.
|
|
|