Computer Science Canada

input from the user

Author:  princess [ Wed Feb 11, 2004 7:55 pm ]
Post subject:  input from the user

i noe how to get numbers from the user.... but those numbers are only integers how can i make them numbers wit decimals?

Author:  Paul [ Wed Feb 11, 2004 7:57 pm ]
Post subject: 

use double or floot type variables.

Author:  princess [ Wed Feb 11, 2004 7:59 pm ]
Post subject: 

.... ya but how do u change the input from a string to a double??

Author:  Paul [ Wed Feb 11, 2004 8:01 pm ]
Post subject: 

Double.parseDouble or something like that, i forgot the exact cases.

Author:  princess [ Wed Feb 11, 2004 8:06 pm ]
Post subject: 

alrite thanx i'll try it

Author:  Homer_simpson [ Wed Feb 11, 2004 9:20 pm ]
Post subject: 

use JOption.ShowInputDialog

Author:  Paul [ Wed Feb 11, 2004 9:59 pm ]
Post subject: 

That can only input string I though, or if Im mistaken I have to change the tutorial. You still end up use Double.parseDouble.

Author:  Homer_simpson [ Thu Feb 12, 2004 7:33 pm ]
Post subject: 

yeah... why dont u just parse it in?

Author:  wtd [ Thu Feb 12, 2004 9:37 pm ]
Post subject: 

It's not tested, but...

code:
import java.lang.*;
import java.io.*;
import java.util.*;

class Test
{
   public static void main(String[] args)
   {
      BufferedReader keyboard = new BufferedRead(
         new InputStreamReader(System.in));

      // read in a line
      String userInput = keyboard.readLine();
     
      // store the double input
      doube parsedUserInput = Double.parseDouble(userInput);

      // do something with the double
   }
}


: