Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Beginner's question re: using the readLine() method

Reply
Thread Tools

Beginner's question re: using the readLine() method

 
 
Dave
Guest
Posts: n/a
 
      02-11-2008
The program below takes an argument entered at the command line and
simply returns a float variable and then an integer.

public class Changer {
public static void main(String[] arguments) {
if (arguments.length > 0) {
System.out.println("The original value: "
+ arguments[0]);
Float num1 = new Float(arguments[0]);
float num2 = num1.floatValue();
int num3 = (int)num2;
System.out.println("The final value: " + num3);
}
}
}

Now let's say I want to input the argument at the command line, but
rather than doing, say:

C:>java Changer 7 (i.e. entering the argument on the command line
itself) ...

I want the program to request, and then process, the input using the
readLine() method, as follows:

C:> java Changer
> Type a number, please.
> ... and so on ...

My questions are:
(1) What's the syntax I need in order to implement the permutation of
readLine() that I want?
(2) What lines of code must I add to the program and where?


Thanks,
Dave

 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      02-11-2008
Dave wrote:

> My questions are:
> (1) What's the syntax I need in order to implement the permutation of
> readLine() that I want?


<http://java.sun.com/docs/books/tutorial/essential/io/cl.html>
<http://java.sun.com/docs/books/tutorial/essential/io/buffers.html>

> (2) What lines of code must I add to the program and where?
>


Learn to do your own homework

http://www.homeworkspot.com/
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      02-11-2008
On Mon, 11 Feb 2008 07:52:36 -0800 (PST), Dave <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>(1) What's the syntax I need in order to implement the permutation of
>readLine() that I want?


see http://mindprod.com/applet/fileio.html

tell it you want to work with a buffered console.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      02-12-2008
Dave wrote:
> Now let's say I want to input the argument at the command line, but
> rather than doing, say:
>
> C:>java Changer 7 (i.e. entering the argument on the command line
> itself) ...
>
> I want the program to request, and then process, the input using the
> readLine() method, as follows:
>
> C:> java Changer
> > Type a number, please.
> > ... and so on ...
>
> My questions are:
> (1) What's the syntax I need in order to implement the permutation of
> readLine() that I want?
> (2) What lines of code must I add to the program and where?


Look at the scanner class.

http://java.sun.com/javase/6/docs/ap...l/Scanner.html

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the Proper Method to Upload Long File - WEBDAV using PUT Method Jitendra Sanghani ASP .Net 1 03-19-2012 09:36 AM
using the current method name within current method Matthew Heidemann Ruby 14 03-22-2011 03:56 AM
Dumb question: in documentation, why Object#method, and not Object.method ? Elf M. Sternberg Ruby 15 07-29-2009 01:20 AM
Using a method as input to another method Erick Star Ruby 3 01-09-2009 06:41 PM
method def in method vs method def in block Kyung won Cheon Ruby 0 11-21-2008 08:48 AM



Advertisments