Hello gurus!
I need a lil help with my program. Its just a piece of code that will compute the 4 basic arithmetic function. but my problem is to display the answer in a single message box.
here's my code below.
import javax.swing.*;
import java.io.*;
public class arithmetic2 {
public static void main( String args[] ) {
String fnum, snum;
float a, b, sum, diff, quot, prod;
fnum = JOptionPane.sho wInputDialog( "Enter first integer" );
snum = JOptionPane.sho wInputDialog( "Enter second integer" );
a = Float.parseFloa t(fnum);
b= Float.parseFloa t(snum);
sum = a + b;
diff = a - b;
quot = a / b;
prod = a * b;
JOptionPane.sho wMessageDialog(
null, "The sum is elvar" +sum, "Results",
JOptionPane.PLA IN_MESSAGE );
JOptionPane.sho wMessageDialog(
null, "The difference is " + diff, "Results",
JOptionPane.PLA IN_MESSAGE );
JOptionPane.sho wMessageDialog(
null, "The quotent is " + quot, "Results",
JOptionPane.PLA IN_MESSAGE );
JOptionPane.sho wMessageDialog(
null, "The product is " + prod, "Results",
JOptionPane.PLA IN_MESSAGE );
System.exit( 0 );
}
}
I used to separate the reuslts in 4 message box. It must be only one.
I need help badly guys.. Thank you.
Oh by the way how do i separate the whole number and the decimal?
like 1.23 it should be
The whole number is: 1
The decimal value is: .23
I'll be waiting for your help and highly appreciate it. Thank you
I need a lil help with my program. Its just a piece of code that will compute the 4 basic arithmetic function. but my problem is to display the answer in a single message box.
here's my code below.
import javax.swing.*;
import java.io.*;
public class arithmetic2 {
public static void main( String args[] ) {
String fnum, snum;
float a, b, sum, diff, quot, prod;
fnum = JOptionPane.sho wInputDialog( "Enter first integer" );
snum = JOptionPane.sho wInputDialog( "Enter second integer" );
a = Float.parseFloa t(fnum);
b= Float.parseFloa t(snum);
sum = a + b;
diff = a - b;
quot = a / b;
prod = a * b;
JOptionPane.sho wMessageDialog(
null, "The sum is elvar" +sum, "Results",
JOptionPane.PLA IN_MESSAGE );
JOptionPane.sho wMessageDialog(
null, "The difference is " + diff, "Results",
JOptionPane.PLA IN_MESSAGE );
JOptionPane.sho wMessageDialog(
null, "The quotent is " + quot, "Results",
JOptionPane.PLA IN_MESSAGE );
JOptionPane.sho wMessageDialog(
null, "The product is " + prod, "Results",
JOptionPane.PLA IN_MESSAGE );
System.exit( 0 );
}
}
I used to separate the reuslts in 4 message box. It must be only one.
I need help badly guys.. Thank you.
Oh by the way how do i separate the whole number and the decimal?
like 1.23 it should be
The whole number is: 1
The decimal value is: .23
I'll be waiting for your help and highly appreciate it. Thank you
Comment