Linux-Noob Forums
coding in java - Printable Version

+- Linux-Noob Forums (https://www.linux-noob.com/forums)
+-- Forum: Distro Noob (https://www.linux-noob.com/forums/forum-10.html)
+--- Forum: Fedora (https://www.linux-noob.com/forums/forum-94.html)
+---- Forum: Fedora Core Release 4 (https://www.linux-noob.com/forums/forum-42.html)
+---- Thread: coding in java (/thread-2183.html)

Pages: 1 2


coding in java - speX - 2006-02-06

my source code as in my java program code? cause my program is extreamly long.... well its a few hundred lines long lol



coding in java - z0ny - 2006-02-06

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. :)



coding in java - speX - 2006-02-07


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){



    }







coding in java - z0ny - 2006-02-07


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+".");
    }
}