Results 1 to 4 of 4
- 11-15-2012, 12:14 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
- 11-15-2012, 12:19 AM #2
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Setting a value from an input in a Command line
Have a look here Command-Line Arguments (The Java™ Tutorials > Essential Classes > The Platform Environment) or search for command line arguments.
- 11-15-2012, 12:06 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Re: Setting a value from an input in a Command line
Here my current code:
I want the values of weigh and age. I don't want actual commands.Java Code:public static void readName(){ System.out.print("What is your name? "); // open up standard input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String userName = null; // read the username from the command-line; need to use try/catch with the // readLine() method try { userName = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read your name!"); System.exit(1); } System.out.println("Thanks for the name, " + userName); } public static void readAge(){ Scanner scan = new Scanner(System.in); System.out.print("What is your age? "); double age = scan.nextDouble(); System.out.println("Your are " + age + " years old"); } public static void readWeight(){ Scanner scan = new Scanner(System.in); System.out.print("What is your age? "); double weigh = scan.nextDouble(); System.out.println("Your weight " + weigh); }Last edited by beastman3226; 11-15-2012 at 12:46 PM.
- 11-15-2012, 12:46 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,451
- Rep Power
- 16
Similar Threads
-
Open a URL and read it line by line (Works in Eclipse but not from Command Line)
By rosco544 in forum NetworkingReplies: 16Last Post: 09-17-2011, 02:41 AM -
command line input to array
By minusten in forum New To JavaReplies: 13Last Post: 05-09-2011, 01:56 AM -
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
Input from Command Line rather than from a text file
By thomas6 in forum New To JavaReplies: 3Last Post: 04-26-2010, 09:00 PM -
Unable to execute command line command in java
By LordSM in forum New To JavaReplies: 1Last Post: 08-08-2007, 12:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks