Hi, I want to practice string and variable handling in small apps. I'd like to know how to read input from the command line once an apps running (I know how to pass in args at the start). I'm thinking along the lines of C++'s ReadFloatPr(" ...."); Thanks
I'm not sure what you mean by 'from the command line'
The only way a java application can read from the command line is through any parameters passed to it...
If you are asking, instead, how to read input from, or write to the console ( the DOS window you are running your java program in ), you would use System.in and System.out...
HTH, -Nate
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Yes that's it. So how would I pass a char from System.in to a switch statement? Would it be like this? switch (System.in){ case 'a': println("You typed 'a'!"); case 'n': ......... }
Obviously switch has to have a char, short, int etc as a variable. So how do I create that variable? char u = System.in(); or something like that? Thanks, Terry
Here's another very simple example I got from an online source -sorry, don't remember where class Echo { public static void main (String [] args) throws java.io.IOException { int ch; System.out.print ("Enter some text: "); while ((ch = System.in.read ()) != '\n') System.out.print ((char) ch); } } This will echo back up to a full line of text (note the '\n').
------------------ I'm a soldier in the NetScape Wars... Joel
Wait a minute, I'm trying to think of something clever to say...<p>Joel
Thank you both very much. I seem to be having the same problem with both examples though. I've copied your codes, compiled them without and problems but on trying to run them they both give this error
Exception in thread "main" java.lang.NoClassDefFoundError: followed by the name of the compiled file. Further help is needed by this beginner. Thanks, Terry
Sound like you need to fix up your classpath. This is what tells the JVM where to go look for all the class to use. In DOS you would say something like: SET CLASSPATH=c:\jdk1.3.0\bin;c:\jdk1.3.0\MyworkingDir You can put this statement in either your autoexec.bat or in a .bat file and execute it in DOS.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Onion rings are vegetable donuts. Taste this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth