Hello I want to write the java, which allow to me to input from Command line two inputs. For exampe: class Hello { puiblic static void main(String arg[]) { } java Hello 2 3 can I change the parameters from String arg[] to int a[], int[]. In other words, how the input program in java works. For example in C++, I wrote cin >> x;
Thanks a lot Can I give to the user,before he or she enter the input some warning like "You can input just two integers" something like that Thanks a lot
Originally posted by Pho Tek: No you may not! That's the public entry point for your class. You need to call Integer.parseInt( arg[i] ) to convert them to ints. Pho
[This message has been edited by Pho Tek (edited October 11, 2001).]
These are two different approaches. Either you can take input parameters when you invoke the program and read them with the args[] array, in which case the user has to type the input BEFORE the program is fired up and therefore can not give any messages.
OR you can have the user start the program with NO input parameters, and then in your main method you can print out your message, and wait for user input using the System.in stream:
"JavaRanch, where the deer and the Certified play" - David O'Meara
It will come in as a String, and you will need to convert it. Use double myDouble = Double.parseDouble(string); for instance Double.parseDouble(args[0]);
You will still need to put it in a try/catch block.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Double.parseDouble(args[0]) give me the error: Mandelbrot.java:7: Method parseDouble(java.lang.String) not found in class java. lang.Double. double cu = Double.parseDouble(arg[0]);