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

Discussion in 'Java' started by Dave, Feb 11, 2008.

  1. Dave

    Dave Guest

    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
     
    Dave, Feb 11, 2008
    #1
    1. Advertising

  2. Dave

    Mark Space Guest

    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/
     
    Mark Space, Feb 11, 2008
    #2
    1. Advertising

  3. Dave

    Roedy Green Guest

    On Mon, 11 Feb 2008 07:52:36 -0800 (PST), Dave <>
    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
     
    Roedy Green, Feb 11, 2008
    #3
  4. Dave

    Arne Vajhøj Guest

    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/api/java/util/Scanner.html

    Arne
     
    Arne Vajhøj, Feb 12, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    593
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  2. cold80

    readLine() method

    cold80, Feb 23, 2005, in forum: Java
    Replies:
    4
    Views:
    3,281
    Stefan Schulz
    Feb 24, 2005
  3. gavino
    Replies:
    4
    Views:
    540
    gavino
    Sep 20, 2010
  4. Jean-Michel
    Replies:
    0
    Views:
    362
    Jean-Michel
    Dec 22, 2007
  5. Andrew DeFaria
    Replies:
    1
    Views:
    212
    Ben Morrow
    Jan 30, 2008
Loading...

Share This Page