Results 1 to 5 of 5

Thread: [JAVA] how do i get the user to input the value of a double? (very new to java)

  1. #1
    Join Date
    Mar 2011
    Beans
    6

    [JAVA] how do i get the user to input the value of a double? (very new to java)

    i'm very new to java, and i can't seem to figure out how to have user input specify the value of a double. i've been trying to use System.in.read();,but when i type in the double (e.g. 3) it will use the ASCII value as the value of the variable instead of what i typed. how do i do this? help!!

    here is what i am trying to use this for; it's a program designed to rate your self esteem by how awesome you think you are.
    Code:
    import java.io.*;
    
    public class AwesomeTest {
        public static void main(String[] args) throws IOException {
     
    
            System.out.println("on a scale of 1 to 10, how awesome are you?");
            double Awesome = System.in.read();
            
            //this next line is just to see if it uses the correct value
            System.out.println(Awesome);
            
            if ((Awesome < 6) && (Awesome > 1)) {
                System.out.println("stop being so emo and get some self esteem. try for like, 6 or above, cause anything below five is just plain emo.");
            }
        
            if ((Awesome > 6) && (Awesome < 11)) {
                System.out.println("that's pretty damn awesome. seriously, you should, like, go for the world record of awesomeness...");
            }
    
            if (Awesome > 11) {
                System.out.println("yeah, nice try buddy. nobody is that awesome. i said on a scale of one to TEN!");
            }
    
            if (Awesome < 1) {
                System.out.println("dude, you need a therapist...");
            }
    
        }
    }

  2. #2
    Join Date
    Jul 2010
    Location
    127.0.0.1
    Beans
    86
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: [JAVA] how do i get the user to input the value of a double? (very new to java)

    Perhaps
    Code:
    string AwesomeTxt = system.in.read();
    int Awsome = AwsomeTxt.toInt();
    A quick-&-dirty solution would be to subtract the ASCII value for 1, but that would cause problems if the user answered something completely batty.
    However, the ubuntu forums do not seem like a good place to be asking questions about Java. Pehaps you should try your questions about Java on Java Forums instead.

  3. #3
    Join Date
    Jun 2007
    Location
    Canada
    Beans
    368
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [JAVA] how do i get the user to input the value of a double? (very new to java)

    Provided you can read in a string then you can use Double.parseDouble(str) to conver the string to its equivalent double value. That may be the easiest solution.
    GCS/O d+(-@) s: a-->? C(++) UL P+ L+++@ E@
    W++$ N++ !o K++ w(++) !O M(-) !V PS+(++)
    PE-() Y+ PGP++ t++(+++@)* 5++ X++@ R+++@
    tv+ b++(+++) DI++ D+ G+ e++>++++ h- r y?

  4. #4
    Join Date
    Oct 2008
    Location
    Maryland, USA
    Beans
    300
    Distro
    Kubuntu 9.10 Karmic Koala

    Re: [JAVA] how do i get the user to input the value of a double? (very new to java)

    Look at the Scanner method nextDouble().

    I recommend that you ask your future programming questions in the Programming Talk subforum here on UF. There are many smart, helpful people who frequent that area.
    OpenSUSE: Dell Inspiron 8600 and Gateway GT5678
    MacOS X 10.5.8 PowerBook G4 12"
    Linux user #: 501795

  5. #5
    Join Date
    Mar 2011
    Beans
    6

    Re: [JAVA] how do i get the user to input the value of a double? (very new to java)

    thanks guys!!! the nextDouble(); thing worked. you all get popcorn


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •