Java equivalent of cin

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gregory W. Ernest

    #1

    Java equivalent of cin

    I am new to Java programming and I was wondering if anyone can tell me the
    java equivalent to a cin>>...; that is normally used in c++. I want to get
    user input and automatically assign it to a variable. So in other words what
    would be the equivant java statement of this c++ statement:

    1: cout<<"Enter a number.";
    2: cin>>x; //This is what I really want to know. I already know the java
    equivalent of the first statement.



  • Wiseguy

    #2
    Re: Java equivalent of cin

    "Gregory W. Ernest" <Gernest@optonl ine.net> wrote in
    news:KR_Gd.7781 $Wz7.1210@fe10. lga:
    [color=blue]
    > I am new to Java programming and I was wondering if anyone can tell me
    > the java equivalent to a cin>>...; that is normally used in c++. I
    > want to get user input and automatically assign it to a variable. So
    > in other words what would be the equivant java statement of this c++
    > statement:
    >
    > 1: cout<<"Enter a number.";
    > 2: cin>>x; //This is what I really want to know. I already know the
    > java equivalent of the first statement.[/color]

    Are you looking for something like?

    byte [] b=new byte[255];
    System.in.read( b);

    I strongly recommend that you download the J2SDK HTML documentation and
    put in on your machine. You then have the complete class heirarchy
    reference available to view at will.




    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= East/West-Coast Server Farms - Total Privacy via Encryption =---

    Comment

    • Sharp

      #3
      Re: Java equivalent of cin

      [color=blue][color=green]
      > > I am new to Java programming and I was wondering if anyone can tell me
      > > the java equivalent to a cin>>...; that is normally used in c++. I
      > > want to get user input and automatically assign it to a variable. So
      > > in other words what would be the equivant java statement of this c++
      > > statement:
      > >
      > > 1: cout<<"Enter a number.";
      > > 2: cin>>x; //This is what I really want to know. I already know the
      > > java equivalent of the first statement.[/color]
      >
      > Are you looking for something like?
      >
      > byte [] b=new byte[255];
      > System.in.read( b);
      >
      > I strongly recommend that you download the J2SDK HTML documentation and
      > put in on your machine. You then have the complete class heirarchy
      > reference available to view at will.[/color]

      That doesn't seem too efficient

      Regards
      Michael



      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.841 / Virus Database: 572 - Release Date: 21/01/2005


      Comment

      • Wiseguy

        #4
        Re: Java equivalent of cin

        "Sharp" <Sharp@SharpAdd ress.com> wrote in news:YIBId.1298 30$K7.120029
        @news-server.bigpond. net.au:
        [color=blue][color=green]
        >>
        >> Are you looking for something like?
        >>
        >> byte [] b=new byte[255];
        >> System.in.read( b);
        >>
        >> I strongly recommend that you download the J2SDK HTML documentation[/color][/color]
        and[color=blue][color=green]
        >> put in on your machine. You then have the complete class heirarchy
        >> reference available to view at will.[/color]
        >
        > That doesn't seem too efficient[/color]

        As opposed to what? Use of a fixed length buffer? explicit necessity to
        type cast the result to some other type?...what then?

        IMHO, streams under java are ugly to begin with.


        Comment

        • Randolf Richardson

          #5
          Re: Java equivalent of cin

          "Wiseguy <noone@all.com> " wrote in comp.lang.java:
          [color=blue]
          > "Sharp" <Sharp@SharpAdd ress.com> wrote in news:YIBId.1298 30$K7.120029
          > @news-server.bigpond. net.au:
          >[color=green][color=darkred]
          >>> Are you looking for something like?
          >>>
          >>> byte [] b=new byte[255];
          >>> System.in.read( b);
          >>>
          >>> I strongly recommend that you download the J2SDK HTML documentation
          >>> and put in on your machine. You then have the complete class
          >>> heirarchy reference available to view at will.[/color]
          >>
          >> That doesn't seem too efficient[/color]
          >
          > As opposed to what? Use of a fixed length buffer? explicit necessity to
          > type cast the result to some other type?...what then?[/color]

          Perhaps "java.io.Buffer edReader" might address the efficiency concern?
          I wonder if "Sharp" needs to read line-by-line.
          [color=blue]
          > IMHO, streams under java are ugly to begin with.[/color]

          Streams aren't the only thing, but then again there are many ugly
          things in many languages. I think Java's Generics are even uglier, but they
          will prove to be very beneficial in the long run.

          --
          Randolf Richardson, pro-active spam fighter - rr@8x.ca
          Vancouver, British Columbia, Canada

          Sending eMail to other SMTP servers is a privilege.

          Comment

          Working...