hello guys.. i do really need some help here. i have to do the 4 basic mathematical operation by entering 2 numbers with decimal.
example.
1st num: 12.50
2nd num: 6.5
the answer must be in float or double but with my code below, upon entering a double or float numbers it will show this error:
java.lang.NumberFormatException: 2.0
at java.lang.Integer.parseInt(Integer.java:414)
at java.lang.Integer.parseInt(Integer.java:454)
at elvar.promptForInt(elvar.java:46)
at elvar.main(elvar.java:19)
Exception in thread "main"
import java.io.*;
public class elvar {
public static void main (String args[]) {
float a, b;
float sum, diff, quo, prod;
a = promptForInt("Enter 1st integer: ");
b = promptForInt("Enter 2nd integer: ");
sum = a + b;
diff = a - b;
quo = a/b;
prod = a* b;
System.out.println("The total is: " + sum);
System.out.println("The difference is: " + diff);
System.out.println("The quotient is: " + quo);
System.out.println("The product is: " + prod);
}
static float promptForInt(String prompt) {
System.out.print(prompt);
System.out.flush();
String s= "";
BufferedReader ds =
new BufferedReader(new InputStreamReader(System.in));
try {
s = ds.readLine();
} catch (IOException e){
System.out.println(e);
}
return Integer.parseInt(s);
}
i really appreciate some help guys. thanx a lot in advance.
}