- 2,491
So I'm currently working on a Java program and I've ran into a snag. My problem is as follows... I want to take a number that has been input from the keyboard and assign it to a variable to use that variable to compute something else in another method (of double data type). What I need to do is to take keyboard input and basically convert it to Java's double data type.
However, the current form of the method seems to return some number (not entered by the user/me) everytime regardless of what is input for some reason. Help would be greatly appreciated as I am not very skilled at doing any sort of user/file input right now.
This is what I have so far (modified from another function in my program that does work):
However, the current form of the method seems to return some number (not entered by the user/me) everytime regardless of what is input for some reason. Help would be greatly appreciated as I am not very skilled at doing any sort of user/file input right now.
This is what I have so far (modified from another function in my program that does work):
Code:
import java.io.*;
class User {
public double inputAmt() {
DataInputStream inputCommand = new DataInputStream(System.in);
double input = 0;
try {
input = (double) inputCommand.read();
} catch(IOException ioe) {
System.out.println(ioe.getMessage());
}
return input;
}
}