Click to See Complete Forum and Search --> : Keyboard input


acemo
10-10-2006, 09:05 AM
I am working on a school project, make a yahtzee game in Java.
Here for i need to use input from the keyboard.
I managed to get some keyboard input/output program working.
But I still fail to use this in a further program.
here is the code i found.

import java.io.*;

public class InvoerToetsenbord
{
public static void main ( String [] args)
{
BufferedReader toetsenbord = new Buffered Reader ( new InputStreamReader ( System.in ) );
int i = 0;
double d = 0.0;
System.out.println ( "Toetsenbord gemaakt" );

try
{
String s = toetsenbord.readLine();
System.out.println("U wrote " + s);
}
catch ( IOException ioe )
{
System.out.println ( "Fout bij inlezen" );
}
}

}

I think the following code declares where a program starts instead of a normal method is being declared.
public static void main(String[] args)

Am i right with this, or what does it means?
Gonna try some more, see if i can fix it before i get an answer here =)

Khalid Ali
10-10-2006, 10:32 AM
yes thats exactly it means, the program starts from this method. Second to get continuous input from user, you will require to run your code in a loop..

acemo
10-10-2006, 11:15 AM
Its obvious u need a loop to get a continuous input.

That was the whole problem we had cuz we are at captor 5 and at captor 12 it tells u how to get user input.

so we had to copy the script from captor 12 and try to adjust it to work for us.

When I noticed the public static void main ( String [] args) is for starting the program, it was alot more easy to do.

We managed to get a continuous input and we can process this input aswell.

We should have finished the application tomorrow.

agent_x91
10-11-2006, 06:00 AM
Good luck. By the way this section of code:


catch ( IOException ioe )
{
System.out.println ( "Fout bij inlezen" );
}



Generally it is good practice to use ioe.printStackTrace(); here, so that it is clear exactly where the exception originated, although it's not actually necessary.