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.Numbe rFormatExceptio n: 2.0
at java.lang.Integ er.parseInt(Int eger.java:414)
at java.lang.Integ er.parseInt(Int eger.java:454)
at elvar.promptFor Int(elvar.java: 46)
at elvar.main(elva r.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("E nter 1st integer: ");
b = promptForInt("E nter 2nd integer: ");
sum = a + b;
diff = a - b;
quo = a/b;
prod = a* b;
System.out.prin tln("The total is: " + sum);
System.out.prin tln("The difference is: " + diff);
System.out.prin tln("The quotient is: " + quo);
System.out.prin tln("The product is: " + prod);
}
static float promptForInt(St ring prompt) {
System.out.prin t(prompt);
System.out.flus h();
String s= "";
BufferedReader ds =
new BufferedReader( new InputStreamRead er(System.in));
try {
s = ds.readLine();
} catch (IOException e){
System.out.prin tln(e);
}
return Integer.parseIn t(s);
}
i really appreciate some help guys. thanx a lot in advance.
}
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.Numbe rFormatExceptio n: 2.0
at java.lang.Integ er.parseInt(Int eger.java:414)
at java.lang.Integ er.parseInt(Int eger.java:454)
at elvar.promptFor Int(elvar.java: 46)
at elvar.main(elva r.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("E nter 1st integer: ");
b = promptForInt("E nter 2nd integer: ");
sum = a + b;
diff = a - b;
quo = a/b;
prod = a* b;
System.out.prin tln("The total is: " + sum);
System.out.prin tln("The difference is: " + diff);
System.out.prin tln("The quotient is: " + quo);
System.out.prin tln("The product is: " + prod);
}
static float promptForInt(St ring prompt) {
System.out.prin t(prompt);
System.out.flus h();
String s= "";
BufferedReader ds =
new BufferedReader( new InputStreamRead er(System.in));
try {
s = ds.readLine();
} catch (IOException e){
System.out.prin tln(e);
}
return Integer.parseIn t(s);
}
i really appreciate some help guys. thanx a lot in advance.
}
Comment