Elijah Lofgren

I follow Jesus Christ and enjoy talking with people, taking pictures, reading, writing, helping people, and making websites. Who is Jesus?

My life mission: "Whatever you do, do it all for the glory of God." - 1 Corinthians 10:31

You are here: Home » Java Tips

Contents

Java Tips

Avoid typing in user input every time you run your program

Modified: 2007-04-23 23:21:12

From #letu on irc.freenode.net:

22:12 < SirAlaran> Tip of the day:
22:12 < SirAlaran> To avoid typing in user input every time you run your
                   program, you can do something like this:
22:12 < SirAlaran> echo "csedegree.prj" | java Main
22:17 < SirAlaran> There's a better way though.
22:17 < SirAlaran> Stick all your sample input in a text file.
22:17 < SirAlaran> java Main < testFile.txt

This tip was originally from Dr. Baas.

Convert a double to an int

Modified: 2007-04-26 21:56:03

If x is a double variable, just cast it to an int like this:
 (int)x

Example Java Applet with GUI Buttons

Modified: 2007-04-27 13:49:48

Here is the applet version of the last program I wrote for Computer Science 2: Graph Lines. I've also made the code available..

    follow me on Twitter