project wont run when I use nextInt()
Has anyone had the problem where when they use nextInt() where the project never runs? I run the project without the nextInt() statements and it builds then runs fine. However when I put in the nextInt() the project just shows that it is building, and never runs. Anyone know whats up?
[292 byte] By [
pberardi1a] at [2007-11-27 10:28:31]

You haven't provided anywhere near enough information, so all I can do is guess that maybe it's waiting for you to enter an integer and hit return.
jverda at 2007-7-28 17:52:10 >

The exact code runs fine in jGrasp. When I try to run it in JSE this is what i get....
init:
deps-jar:
compile:
run:
and at the bottom it says building Wages(run)...
import java.util.Scanner;
import java.text.NumberFormat;
public class Wages {
/** Creates a new instance of Wages */
public Wages() {
}
public static void main(String[]args){
final double RATE = 8.25;
final int STANDARD =40;
Scanner scan = new Scanner (System.in);
double pay = 0.0;
System.out.print ("Enter the number of hours worked: ");
int hours = scan.nextInt();
System.out.println();
if(hours>STANDARD)
pay= STANDARD*RATE + (hours-STANDARD) * (RATE*1.5);
else
pay = hours * RATE;
NumberFormat fmt = NumberFormat.getCurrencyInstance();
System.out.println("Gross earnings: "+fmt.format(pay));
}
}
I have no idea what you mean by running it "in JSE."
1) Call System.out.flush() after print() if you're not seeing output.
2) Make sure you're entering an integer and hitting return.
jverda at 2007-7-28 17:52:10 >

This is so weird. I mean java studio enterprise by the way. I used a println instead of a print and then it read the line.
More specifically: System.out.println ("Enter the number of hours worked: ");
Println flushes. Print doesn't, so you'll sometimes have to explicitly flush if you use it.
jverda at 2007-7-28 17:52:10 >

not that its that big of a deal but it still does not print.
System.out.print ("Enter the number of hours worked: ");
System.out.flush() ;
At this point in my java knowledge I do not know why it would make a difference whether I use a print or a println because from what i understand println is just a carriage return. Now i know that it also flushes but I am not sure what that means.
> not that its that big of a deal but it still does not
> print.
>
Weird. I'm not sure why. Maybe JSE's console is buggy.
What happens when you run it on the command line?
> flushes but I am not sure what that means.
When you write something to a stream or writer, it doesn't necessarily go immediately to the ultimate destination (screen, disk, network). Instead, the bytes may be buffered until the buffer fills up or until you explicitly flush it (write its bytes to the next stage). This is because actually writing to the I/O system carries overhead, so you'd rather write a bunch of bytes at once than individually.
jverda at 2007-7-28 17:52:10 >

I am glad you asked that question about the command line because i was wondering if you could teach me how to do that? I did it once but only under the direction of my instructor. I am doing these on my own so...he aint around anymore. i dont have that much command line experience so if you could help that would be great
If your class is not in a package, and you have MyClass.class in your current directory, then
java -cp . MyClass
jverda at 2007-7-28 17:52:10 >

If my path is C:Practice Java\Wages how do i get that directory in the command line when i am at the C:\>
When i type in what you said to jverd, i am getting could not create the virtual machine
> If my path is C:Practice Java\Wages how do i get
> that directory in the command line when i am at the
> C:\>
cd \Practice Java\Wages
Although you might need to put it in quotes or put a \ before the space.
jverda at 2007-7-28 17:52:10 >

> When i type in what you said to jverd, i am getting
> could not create the virtual machine
Unless you paste in exactly what you're doing and the exact, complete error message, I have no idea what th problem is.
jverda at 2007-7-28 17:52:10 >
