Linux-Noob Forums

Full Version: coding in java
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
my source code as in my java program code? cause my program is extreamly long.... well its a few hundred lines long lol
That's why I said the *relevant* source code, not the entire one. ;) My guess is that you assign the input directly to an integer variable though it gets read as a string. Maybe your Windows JVM automatically converts the input. But show me the source, Luke. :)

here it is the menu part



Code:
/Main Menu System.out.println ("Please select a option"); System.out.println ("1. Play Game"); System.out.println ("2. Instructions"); System.out.println ("3. High Scores"); System.out.println ("4. Exit"); intInput = reader.readInt(); //Menu Choices if (intInput == 1){ PlayGame(); }else if (intInput == 2){ strInstructions(); }else if (intInput == 3){ HighScores(); }else if (intInput == 4){ }





The data type of your "reader" variable would be interesting, too. I just wrote a small example that *should* work (will test it later, not too much time at the moment):

 



Code:
import java.io.*; public class myinput { static public void main(String[] args) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int someint = 0; System.out.print("Number: "); try { someint = Integer.parseInt(reader.readLine()); } catch (IOException e) { System.out.println("Input error..."); System.exit(1); } System.out.println("Entered "+someint+"."); } }




Pages: 1 2