import javax.swing.JOptionPane;
public class HW {
public static void main(String[] args)
{
String x1 = JOptionPane.showInputDialog(null, "X: ");
String y1 = JOptionPane.showInputDialog(null, "Y: ");
double x = Double.parseDouble(x1);
double y = Double.parseDouble(y1);
System.out.println("Sum: " + (x+y));
System.out.println("Difference: " + (x-y));
System.out.println("Product: " + (x*y));
System.out.println("Average: " + (x+y)/2);
System.out.println("Distance: " + Math.abs(x-y));
System.out.println("Maximum Value: " + Math.max(x,y));
System.out.println("Minimum Value: " + Math.min(x,y));
}
}
基本上,我试图将值输出为:
Sum: 5
Difference: 10
Product: 7
etc.
我已经找到了如何使用字符串来做到这一点,但我不确定如何使用变量来实现这一点。